boundary.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. #include <boost/locale.hpp>
  9. #include <iostream>
  10. #include <cassert>
  11. #include <ctime>
  12. int main()
  13. {
  14. using namespace boost::locale;
  15. using namespace std;
  16. generator gen;
  17. // Make system default locale global
  18. std::locale loc = gen("");
  19. locale::global(loc);
  20. cout.imbue(loc);
  21. string text="Hello World! あにま! Linux2.6 and Windows7 is word and number. שָלוֹם עוֹלָם!";
  22. cout<<text<<endl;
  23. boundary::ssegment_index index(boundary::word,text.begin(),text.end());
  24. boundary::ssegment_index::iterator p,e;
  25. for(p=index.begin(),e=index.end();p!=e;++p) {
  26. cout<<"Part ["<<*p<<"] has ";
  27. if(p->rule() & boundary::word_number)
  28. cout<<"number(s) ";
  29. if(p->rule() & boundary::word_letter)
  30. cout<<"letter(s) ";
  31. if(p->rule() & boundary::word_kana)
  32. cout<<"kana character(s) ";
  33. if(p->rule() & boundary::word_ideo)
  34. cout<<"ideographic character(s) ";
  35. if(p->rule() & boundary::word_none)
  36. cout<<"no word characters";
  37. cout<<endl;
  38. }
  39. index.map(boundary::character,text.begin(),text.end());
  40. for(p=index.begin(),e=index.end();p!=e;++p) {
  41. cout<<"|" <<*p ;
  42. }
  43. cout<<"|\n\n";
  44. index.map(boundary::line,text.begin(),text.end());
  45. for(p=index.begin(),e=index.end();p!=e;++p) {
  46. cout<<"|" <<*p ;
  47. }
  48. cout<<"|\n\n";
  49. index.map(boundary::sentence,text.begin(),text.end());
  50. for(p=index.begin(),e=index.end();p!=e;++p) {
  51. cout<<"|" <<*p ;
  52. }
  53. cout<<"|\n\n";
  54. }
  55. // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
  56. // boostinspect:noascii