grapheme_api.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. #############################################################################
  3. # Grapheme constants.
  4. #############################################################################
  5. /**
  6. * grapheme_extract extract_type
  7. *
  8. */
  9. /** Extract the given number of whole grapheme clusters from the string: */
  10. define('GRAPHEME_EXTR_COUNT', 0);
  11. /** Extract as many whole grapheme clusters as will fit into the given number of bytes: */
  12. define('GRAPHEME_EXTR_MAXBYTES', 1);
  13. /** Extract whole grapheme clusters up to a maximum number of UTF-8 characters: */
  14. define('GRAPHEME_EXTR_MAXCHARS', 2);
  15. #############################################################################
  16. # Grapheme API
  17. #############################################################################
  18. /**
  19. * Get string length in grapheme units
  20. * @param string $input The string being measured for length.
  21. * @return int The length of the string on success, and 0 if the string is empty.
  22. */
  23. function grapheme_strlen($input) {}
  24. /**
  25. * Find position (in grapheme units) of first occurrence of a string
  26. * @param string $haystack The string to look in
  27. * @param string $needle The string to look for
  28. * @param [int] $offset The optional offset parameter allows you to specify
  29. which character in haystack to start searching. The position
  30. returned is still relative to the beginning of haystack.
  31. * @return int Returns the position as an integer. If needle is not found, strpos() will return boolean FALSE.
  32. */
  33. function grapheme_strpos($haystack, $needle, $offset = 0) {}
  34. /**
  35. * Find position (in grapheme units) of first occurrence of a case-insensitive string
  36. * @param string $haystack The string to look in
  37. * @param string $needle The string to look for
  38. * @param [int] $offset The optional offset parameter allows you to specify
  39. which character in haystack to start searching. The position
  40. returned is still relative to the beginning of haystack.
  41. * @return int Returns the position as an integer. If needle is not found, grapheme_stripos() will return boolean FALSE.
  42. */
  43. function grapheme_stripos($haystack, $needle, $offset = 0) {}
  44. /**
  45. * Find position (in grapheme units) of last occurrence of a string
  46. * @param string $haystack The string to look in
  47. * @param string $needle The string to look for
  48. * @param [int] $offset The optional offset parameter allows you to specify
  49. which character in haystack to start searching. The position
  50. returned is still relative to the beginning of haystack.
  51. * @return int Returns the position as an integer. If needle is not found, grapheme_strrpos() will return boolean FALSE.
  52. */
  53. function grapheme_strrpos($haystack, $needle, $offset = 0) {}
  54. /**
  55. * Find position (in grapheme units) of last occurrence of a case-insensitive string
  56. * @param string $haystack The string to look in
  57. * @param string $needle The string to look for
  58. * @param [int] $offset The optional offset parameter allows you to specify
  59. which character in haystack to start searching. The position
  60. returned is still relative to the beginning of haystack.
  61. * @return int Returns the position as an integer. If needle is not found, grapheme_strripos() will return boolean FALSE.
  62. */
  63. function grapheme_strripos($haystack, $needle, $offset = 0) {}
  64. /**
  65. * Return part of a string
  66. * @param string $string The input string.
  67. * @param int $start If start is non-negative, the returned string will start at the
  68. start'th position in string, counting from zero. If start is negative,
  69. the returned string will start at the start'th character from the
  70. end of string.
  71. * @param [int] $length If length is given and is positive, the string returned will contain
  72. at most length characters beginning from start (depending on the
  73. length of string). If string is less than or equal to start characters
  74. long, FALSE will be returned. If length is given and is negative, then
  75. that many characters will be omitted from the end of string (after the
  76. start position has been calculated when a start is negative). If start
  77. denotes a position beyond this truncation, an empty string will be returned.
  78. * @return int Returns the extracted part of string.
  79. */
  80. function grapheme_substr($string, $start, $length = -1) {}
  81. /**
  82. * Returns part of haystack string from the first occurrence of needle to the end of haystack.
  83. * @param string $haystack The input string.
  84. * @param string $needle The string to look for.
  85. * @param [boolean] $before_needle If TRUE (the default is FALSE), grapheme_strstr() returns the part of the
  86. haystack before the first occurrence of the needle.
  87. * @return string Returns the portion of string, or FALSE if needle is not found.
  88. */
  89. function grapheme_strstr($haystack, $needle, $before_needle = FALSE) {}
  90. /**
  91. * Returns part of haystack string from the first occurrence of case-insensitive needle to the end of haystack.
  92. * @param string $haystack The input string.
  93. * @param string $needle The string to look for.
  94. * @param [boolean] $before_needle If TRUE (the default is FALSE), grapheme_strstr() returns the part of the
  95. haystack before the first occurrence of the needle.
  96. * @return string Returns the portion of string, or FALSE if needle is not found.
  97. */
  98. function grapheme_stristr($haystack, $needle, $before_needle = FALSE) {}
  99. /**
  100. * Function to extract a sequence of default grapheme clusters from a text buffer, which must be encoded in UTF-8.
  101. * @param string $haystack string to search
  102. * @param int $size maximum number of units - based on the $extract_type - to return
  103. * @param [int] $extract_type one of GRAPHEME_EXTR_COUNT (default), GRAPHEME_EXTR_MAXBYTES, or GRAPHEME_EXTR_MAXCHARS
  104. * @param [int] $start starting position in $haystack in bytes
  105. * @param [&int] $next set to next starting position in bytes
  106. * @return string A string starting at offset $start containing no more than $size grapheme clusters
  107. and ending on a default grapheme cluster boundary.
  108. */
  109. function grapheme_extract($haystack, $size, $extract_type = GRAPHEME_EXTR_COUNT, $start = 0, &$next) {}
  110. ?>