cpbi_getLastCodePoint_basic.phpt 1.9 KB

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