cpbi_getLastCodePoint_basic.phpt 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. --TEST--
  2. IntlCodepointBreakIterator::getLastCodePoint(): basic test
  3. --EXTENSIONS--
  4. intl
  5. --FILE--
  6. <?php
  7. ini_set("intl.error_level", E_WARNING);
  8. ini_set("intl.default_locale", "pt_PT");
  9. $text = 'ตัวอย่างข้อความ';
  10. $codepoint_it = IntlBreakIterator::createCodePointInstance();
  11. $codepoint_it->setText($text);
  12. var_dump($codepoint_it->getLastCodePoint());
  13. //first() and last() don't read codepoint and set the last code point var to -1
  14. //The pointer is after the last read codepoint if moving forward and
  15. //before the last read codepoint is moving backwards
  16. $p = $codepoint_it->first();
  17. while ($p != IntlBreakIterator::DONE) {
  18. $c = $codepoint_it->getLastCodePoint();
  19. if ($c > 0)
  20. var_dump(sprintf('U+%04X', $codepoint_it->getLastCodePoint()));
  21. else
  22. var_dump($c);
  23. //it's a post-increment operation as to the codepoint, i.e., it gives the codepoint
  24. //starting at the initial position and only then moves the pointer forward
  25. $p = $codepoint_it->next();
  26. }
  27. echo "Now backwards\n";
  28. $p = $codepoint_it->last();
  29. while ($p != IntlBreakIterator::DONE) {
  30. $c = $codepoint_it->getLastCodePoint();
  31. if ($c > 0)
  32. var_dump(sprintf('U+%04X', $codepoint_it->getLastCodePoint()));
  33. else
  34. var_dump($c);
  35. $p = $codepoint_it->previous();
  36. }
  37. ?>
  38. --EXPECT--
  39. int(-1)
  40. int(-1)
  41. string(6) "U+0E15"
  42. string(6) "U+0E31"
  43. string(6) "U+0E27"
  44. string(6) "U+0E2D"
  45. string(6) "U+0E22"
  46. string(6) "U+0E48"
  47. string(6) "U+0E32"
  48. string(6) "U+0E07"
  49. string(6) "U+0E02"
  50. string(6) "U+0E49"
  51. string(6) "U+0E2D"
  52. string(6) "U+0E04"
  53. string(6) "U+0E27"
  54. string(6) "U+0E32"
  55. string(6) "U+0E21"
  56. Now backwards
  57. int(-1)
  58. string(6) "U+0E21"
  59. string(6) "U+0E32"
  60. string(6) "U+0E27"
  61. string(6) "U+0E04"
  62. string(6) "U+0E2D"
  63. string(6) "U+0E49"
  64. string(6) "U+0E02"
  65. string(6) "U+0E07"
  66. string(6) "U+0E32"
  67. string(6) "U+0E48"
  68. string(6) "U+0E22"
  69. string(6) "U+0E2D"
  70. string(6) "U+0E27"
  71. string(6) "U+0E31"
  72. string(6) "U+0E15"