| 1 |
// Copyright 2006 The Closure Library Authors. All Rights Reserved. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS-IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
/** |
| 16 |
* @fileoverview Detect Grapheme Cluster Break in a pair of codepoints. Follows |
| 17 |
* Unicode 10 UAX#29. Tailoring for Virama × Indic Letters is used. |
| 18 |
* |
| 19 |
* Reference: http://unicode.org/reports/tr29 |
| 20 |
* |
| 21 |
*/ |
| 22 |
|
| 23 |
goog.provide('goog.i18n.GraphemeBreak'); |
| 24 |
|
| 25 |
goog.require('goog.asserts'); |
| 26 |
goog.require('goog.i18n.uChar'); |
| 27 |
goog.require('goog.structs.InversionMap'); |
| 28 |
|
| 29 |
/** |
| 30 |
* Enum for all Grapheme Cluster Break properties. |
| 31 |
* These enums directly corresponds to Grapheme_Cluster_Break property values |
| 32 |
* mentioned in http://unicode.org/reports/tr29 table 2. VIRAMA and |
| 33 |
* INDIC_LETTER are for the Virama × Base tailoring mentioned in the notes. |
| 34 |
* |
| 35 |
* @protected @enum {number} |
| 36 |
*/ |
| 37 |
goog.i18n.GraphemeBreak.property = { |
| 38 |
OTHER: 0, |
| 39 |
CONTROL: 1, |
| 40 |
EXTEND: 2, |
| 41 |
PREPEND: 3, |
| 42 |
SPACING_MARK: 4, |
| 43 |
INDIC_LETTER: 5, |
| 44 |
VIRAMA: 6, |
| 45 |
L: 7, |
| 46 |
V: 8, |
| 47 |
T: 9, |
| 48 |
LV: 10, |
| 49 |
LVT: 11, |
| 50 |
CR: 12, |
| 51 |
LF: 13, |
| 52 |
REGIONAL_INDICATOR: 14, |
| 53 |
ZWJ: 15, |
| 54 |
E_BASE: 16, |
| 55 |
GLUE_AFTER_ZWJ: 17, |
| 56 |
E_MODIFIER: 18, |
| 57 |
E_BASE_GAZ: 19 |
| 58 |
}; |
| 59 |
|
| 60 |
|
| 61 |
/** |
| 62 |
* Grapheme Cluster Break property values for all codepoints as inversion map. |
| 63 |
* Constructed lazily. |
| 64 |
* |
| 65 |
* @private {?goog.structs.InversionMap} |
| 66 |
*/ |
| 67 |
goog.i18n.GraphemeBreak.inversions_ = null; |
| 68 |
|
| 69 |
|
| 70 |
/** |
| 71 |
* Indicates if a and b form a grapheme cluster. |
| 72 |
* |
| 73 |
* This implements the rules in: |
| 74 |
* http://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundary_Rules |
| 75 |
* |
| 76 |
* @param {number|string} a Code point or string with the first side of |
| 77 |
* grapheme cluster. |
| 78 |
* @param {number|string} b Code point or string with the second side of |
| 79 |
* grapheme cluster. |
| 80 |
* @param {boolean} extended If true, indicates extended grapheme cluster; |
| 81 |
* If false, indicates legacy cluster. |
| 82 |
* @return {boolean} True if a & b do not form a cluster; False otherwise. |
| 83 |
* @private |
| 84 |
*/ |
| 85 |
goog.i18n.GraphemeBreak.applyBreakRules_ = function(a, b, extended) { |
| 86 |
var prop = goog.i18n.GraphemeBreak.property; |
| 87 |
|
| 88 |
var aCode = goog.isString(a) ? |
| 89 |
goog.i18n.GraphemeBreak.getCodePoint_(a, a.length - 1) : |
| 90 |
a; |
| 91 |
var bCode = |
| 92 |
goog.isString(b) ? goog.i18n.GraphemeBreak.getCodePoint_(b, 0) : b; |
| 93 |
|
| 94 |
var aProp = goog.i18n.GraphemeBreak.getBreakProp_(aCode); |
| 95 |
var bProp = goog.i18n.GraphemeBreak.getBreakProp_(bCode); |
| 96 |
|
| 97 |
var isString = goog.isString(a); |
| 98 |
|
| 99 |
// GB3. |
| 100 |
if (aProp === prop.CR && bProp === prop.LF) { |
| 101 |
return false; |
| 102 |
} |
| 103 |
|
| 104 |
// GB4. |
| 105 |
if (aProp === prop.CONTROL || aProp === prop.CR || aProp === prop.LF) { |
| 106 |
return true; |
| 107 |
} |
| 108 |
|
| 109 |
// GB5. |
| 110 |
if (bProp === prop.CONTROL || bProp === prop.CR || bProp === prop.LF) { |
| 111 |
return true; |
| 112 |
} |
| 113 |
|
| 114 |
// GB6. |
| 115 |
if (aProp === prop.L && |
| 116 |
(bProp === prop.L || bProp === prop.V || bProp === prop.LV || |
| 117 |
bProp === prop.LVT)) { |
| 118 |
return false; |
| 119 |
} |
| 120 |
|
| 121 |
// GB7. |
| 122 |
if ((aProp === prop.LV || aProp === prop.V) && |
| 123 |
(bProp === prop.V || bProp === prop.T)) { |
| 124 |
return false; |
| 125 |
} |
| 126 |
|
| 127 |
// GB8. |
| 128 |
if ((aProp === prop.LVT || aProp === prop.T) && bProp === prop.T) { |
| 129 |
return false; |
| 130 |
} |
| 131 |
|
| 132 |
// GB9. |
| 133 |
if (bProp === prop.EXTEND || bProp === prop.ZWJ || bProp === prop.VIRAMA) { |
| 134 |
return false; |
| 135 |
} |
| 136 |
|
| 137 |
// GB9a, GB9b. |
| 138 |
if (extended && (aProp === prop.PREPEND || bProp === prop.SPACING_MARK)) { |
| 139 |
return false; |
| 140 |
} |
| 141 |
|
| 142 |
// Tailorings for basic aksara support. |
| 143 |
if (extended && aProp === prop.VIRAMA && bProp === prop.INDIC_LETTER) { |
| 144 |
return false; |
| 145 |
} |
| 146 |
|
| 147 |
var aStr, index, codePoint, codePointProp; |
| 148 |
|
| 149 |
// GB10. |
| 150 |
if (isString) { |
| 151 |
if (bProp === prop.E_MODIFIER) { |
| 152 |
// If using new API, consume the string's code points starting from the |
| 153 |
// end and test the left side of: (E_Base | EBG) Extend* × E_Modifier. |
| 154 |
aStr = /** @type {string} */ (a); |
| 155 |
index = aStr.length - 1; |
| 156 |
codePoint = aCode; |
| 157 |
codePointProp = aProp; |
| 158 |
while (index > 0 && codePointProp === prop.EXTEND) { |
| 159 |
index -= goog.i18n.uChar.charCount(codePoint); |
| 160 |
codePoint = goog.i18n.GraphemeBreak.getCodePoint_(aStr, index); |
| 161 |
codePointProp = goog.i18n.GraphemeBreak.getBreakProp_(codePoint); |
| 162 |
} |
| 163 |
if (codePointProp === prop.E_BASE || codePointProp === prop.E_BASE_GAZ) { |
| 164 |
return false; |
| 165 |
} |
| 166 |
} |
| 167 |
} else { |
| 168 |
// If using legacy API, return best effort by testing: |
| 169 |
// (E_Base | EBG) × E_Modifier. |
| 170 |
if ((aProp === prop.E_BASE || aProp === prop.E_BASE_GAZ) && |
| 171 |
bProp === prop.E_MODIFIER) { |
| 172 |
return false; |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
// GB11. |
| 177 |
if (aProp === prop.ZWJ && |
| 178 |
(bProp === prop.GLUE_AFTER_ZWJ || bProp === prop.E_BASE_GAZ)) { |
| 179 |
return false; |
| 180 |
} |
| 181 |
|
| 182 |
// GB12, GB13. |
| 183 |
if (isString) { |
| 184 |
if (bProp === prop.REGIONAL_INDICATOR) { |
| 185 |
// If using new API, consume the string's code points starting from the |
| 186 |
// end and test the left side of these rules: |
| 187 |
// - sot (RI RI)* RI × RI |
| 188 |
// - [^RI] (RI RI)* RI × RI. |
| 189 |
var numberOfRi = 0; |
| 190 |
aStr = /** @type {string} */ (a); |
| 191 |
index = aStr.length - 1; |
| 192 |
codePoint = aCode; |
| 193 |
codePointProp = aProp; |
| 194 |
while (index > 0 && codePointProp === prop.REGIONAL_INDICATOR) { |
| 195 |
numberOfRi++; |
| 196 |
index -= goog.i18n.uChar.charCount(codePoint); |
| 197 |
codePoint = goog.i18n.GraphemeBreak.getCodePoint_(aStr, index); |
| 198 |
codePointProp = goog.i18n.GraphemeBreak.getBreakProp_(codePoint); |
| 199 |
} |
| 200 |
if (codePointProp === prop.REGIONAL_INDICATOR) { |
| 201 |
numberOfRi++; |
| 202 |
} |
| 203 |
if (numberOfRi % 2 === 1) { |
| 204 |
return false; |
| 205 |
} |
| 206 |
} |
| 207 |
} else { |
| 208 |
// If using legacy API, return best effort by testing: RI × RI. |
| 209 |
if (aProp === prop.REGIONAL_INDICATOR && |
| 210 |
bProp === prop.REGIONAL_INDICATOR) { |
| 211 |
return false; |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 215 |
// GB999. |
| 216 |
return true; |
| 217 |
}; |
| 218 |
|
| 219 |
|
| 220 |
/** |
| 221 |
* Method to return property enum value of the code point. If it is Hangul LV or |
| 222 |
* LVT, then it is computed; for the rest it is picked from the inversion map. |
| 223 |
* |
| 224 |
* @param {number} codePoint The code point value of the character. |
| 225 |
* @return {number} Property enum value of code point. |
| 226 |
* @private |
| 227 |
*/ |
| 228 |
goog.i18n.GraphemeBreak.getBreakProp_ = function(codePoint) { |
| 229 |
if (0xAC00 <= codePoint && codePoint <= 0xD7A3) { |
| 230 |
var prop = goog.i18n.GraphemeBreak.property; |
| 231 |
if (codePoint % 0x1C === 0x10) { |
| 232 |
return prop.LV; |
| 233 |
} |
| 234 |
return prop.LVT; |
| 235 |
} else { |
| 236 |
if (!goog.i18n.GraphemeBreak.inversions_) { |
| 237 |
goog.i18n.GraphemeBreak.inversions_ = new goog.structs.InversionMap( |
| 238 |
[ |
| 239 |
0, 10, 1, 2, 1, 18, 95, 33, 13, 1, |
| 240 |
594, 112, 275, 7, 263, 45, 1, 1, 1, 2, |
| 241 |
1, 2, 1, 1, 56, 6, 10, 11, 1, 1, |
| 242 |
46, 21, 16, 1, 101, 7, 1, 1, 6, 2, |
| 243 |
2, 1, 4, 33, 1, 1, 1, 30, 27, 91, |
| 244 |
11, 58, 9, 34, 4, 1, 9, 1, 3, 1, |
| 245 |
5, 43, 3, 120, 14, 1, 32, 1, 17, 37, |
| 246 |
1, 1, 1, 1, 3, 8, 4, 1, 2, 1, |
| 247 |
7, 8, 2, 2, 21, 7, 1, 1, 2, 17, |
| 248 |
39, 1, 1, 1, 2, 6, 6, 1, 9, 5, |
| 249 |
4, 2, 2, 12, 2, 15, 2, 1, 17, 39, |
| 250 |
2, 3, 12, 4, 8, 6, 17, 2, 3, 14, |
| 251 |
1, 17, 39, 1, 1, 3, 8, 4, 1, 20, |
| 252 |
2, 29, 1, 2, 17, 39, 1, 1, 2, 1, |
| 253 |
6, 6, 9, 6, 4, 2, 2, 13, 1, 16, |
| 254 |
1, 18, 41, 1, 1, 1, 12, 1, 9, 1, |
| 255 |
40, 1, 3, 17, 31, 1, 5, 4, 3, 5, |
| 256 |
7, 8, 3, 2, 8, 2, 29, 1, 2, 17, |
| 257 |
39, 1, 1, 1, 1, 2, 1, 3, 1, 5, |
| 258 |
1, 8, 9, 1, 3, 2, 29, 1, 2, 17, |
| 259 |
38, 3, 1, 2, 5, 7, 1, 1, 8, 1, |
| 260 |
10, 2, 30, 2, 22, 48, 5, 1, 2, 6, |
| 261 |
7, 1, 18, 2, 13, 46, 2, 1, 1, 1, |
| 262 |
6, 1, 12, 8, 50, 46, 2, 1, 1, 1, |
| 263 |
9, 11, 6, 14, 2, 58, 2, 27, 1, 1, |
| 264 |
1, 1, 1, 4, 2, 49, 14, 1, 4, 1, |
| 265 |
1, 2, 5, 48, 9, 1, 57, 33, 12, 4, |
| 266 |
1, 6, 1, 2, 2, 2, 1, 16, 2, 4, |
| 267 |
2, 2, 4, 3, 1, 3, 2, 7, 3, 4, |
| 268 |
13, 1, 1, 1, 2, 6, 1, 1, 14, 1, |
| 269 |
98, 96, 72, 88, 349, 3, 931, 15, 2, 1, |
| 270 |
14, 15, 2, 1, 14, 15, 2, 15, 15, 14, |
| 271 |
35, 17, 2, 1, 7, 8, 1, 2, 9, 1, |
| 272 |
1, 9, 1, 45, 3, 1, 118, 2, 34, 1, |
| 273 |
87, 28, 3, 3, 4, 2, 9, 1, 6, 3, |
| 274 |
20, 19, 29, 44, 84, 23, 2, 2, 1, 4, |
| 275 |
45, 6, 2, 1, 1, 1, 8, 1, 1, 1, |
| 276 |
2, 8, 6, 13, 48, 84, 1, 14, 33, 1, |
| 277 |
1, 5, 1, 1, 5, 1, 1, 1, 7, 31, |
| 278 |
9, 12, 2, 1, 7, 23, 1, 4, 2, 2, |
| 279 |
2, 2, 2, 11, 3, 2, 36, 2, 1, 1, |
| 280 |
2, 3, 1, 1, 3, 2, 12, 36, 8, 8, |
| 281 |
2, 2, 21, 3, 128, 3, 1, 13, 1, 7, |
| 282 |
4, 1, 4, 2, 1, 3, 2, 198, 64, 523, |
| 283 |
1, 1, 1, 2, 24, 7, 49, 16, 96, 33, |
| 284 |
1324, 1, 34, 1, 1, 1, 82, 2, 98, 1, |
| 285 |
14, 1, 1, 4, 86, 1, 1418, 3, 141, 1, |
| 286 |
96, 32, 554, 6, 105, 2, 30164, 4, 1, 10, |
| 287 |
32, 2, 80, 2, 272, 1, 3, 1, 4, 1, |
| 288 |
23, 2, 2, 1, 24, 30, 4, 4, 3, 8, |
| 289 |
1, 1, 13, 2, 16, 34, 16, 1, 1, 26, |
| 290 |
18, 24, 24, 4, 8, 2, 23, 11, 1, 1, |
| 291 |
12, 32, 3, 1, 5, 3, 3, 36, 1, 2, |
| 292 |
4, 2, 1, 3, 1, 36, 1, 32, 35, 6, |
| 293 |
2, 2, 2, 2, 12, 1, 8, 1, 1, 18, |
| 294 |
16, 1, 3, 6, 1, 1, 1, 3, 48, 1, |
| 295 |
1, 3, 2, 2, 5, 2, 1, 1, 32, 9, |
| 296 |
1, 2, 2, 5, 1, 1, 201, 14, 2, 1, |
| 297 |
1, 9, 8, 2, 1, 2, 1, 2, 1, 1, |
| 298 |
1, 18, 11184, 27, 49, 1028, 1024, 6942, 1, 737, |
| 299 |
16, 16, 16, 207, 1, 158, 2, 89, 3, 513, |
| 300 |
1, 226, 1, 149, 5, 1670, 15, 40, 7, 1, |
| 301 |
165, 2, 1305, 1, 1, 1, 53, 14, 1, 56, |
| 302 |
1, 2, 1, 45, 3, 4, 2, 1, 1, 2, |
| 303 |
1, 66, 3, 36, 5, 1, 6, 2, 62, 1, |
| 304 |
12, 2, 1, 48, 3, 9, 1, 1, 1, 2, |
| 305 |
6, 3, 95, 3, 3, 2, 1, 1, 2, 6, |
| 306 |
1, 160, 1, 3, 7, 1, 21, 2, 2, 56, |
| 307 |
1, 1, 1, 1, 1, 12, 1, 9, 1, 10, |
| 308 |
4, 15, 192, 3, 8, 2, 1, 2, 1, 1, |
| 309 |
105, 1, 2, 6, 1, 1, 2, 1, 1, 2, |
| 310 |
1, 1, 1, 235, 1, 2, 6, 4, 2, 1, |
| 311 |
1, 1, 27, 2, 82, 3, 8, 2, 1, 1, |
| 312 |
1, 1, 106, 1, 1, 1, 2, 6, 1, 1, |
| 313 |
101, 3, 2, 4, 1, 4, 1, 1283, 1, 14, |
| 314 |
1, 1, 82, 23, 1, 7, 1, 2, 1, 2, |
| 315 |
20025, 5, 59, 7, 1050, 62, 4, 19722, 2, 1, |
| 316 |
4, 5313, 1, 1, 3, 3, 1, 5, 8, 8, |
| 317 |
2, 7, 30, 4, 148, 3, 1979, 55, 4, 50, |
| 318 |
8, 1, 14, 1, 22, 1424, 2213, 7, 109, 7, |
| 319 |
2203, 26, 264, 1, 53, 1, 52, 1, 17, 1, |
| 320 |
13, 1, 16, 1, 3, 1, 25, 3, 2, 1, |
| 321 |
2, 3, 30, 1, 1, 1, 13, 5, 66, 2, |
| 322 |
2, 11, 21, 4, 4, 1, 1, 9, 3, 1, |
| 323 |
4, 3, 1, 3, 3, 1, 30, 1, 16, 2, |
| 324 |
106, 1, 4, 1, 71, 2, 4, 1, 21, 1, |
| 325 |
4, 2, 81, 1, 92, 3, 3, 5, 48, 1, |
| 326 |
17, 1, 16, 1, 16, 3, 9, 1, 11, 1, |
| 327 |
587, 5, 1, 1, 7, 1, 9, 10, 3, 2, |
| 328 |
788162, 31 |
| 329 |
], |
| 330 |
[ |
| 331 |
1, 13, 1, 12, 1, 0, 1, 0, 1, 0, 2, 0, 2, 0, 2, 0, 2, 0, |
| 332 |
2, 0, 2, 0, 2, 0, 3, 0, 2,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2, 4, 0, 4, 2, 4, 6, 2, 0, 3, 0, 2, 0, 2, 4, 2, 6, 0, |
| 367 |
2, 0, 2, 4, 0, 4, 2, 4, 6, 0, 3, 0, 2, 0, 4, 2, 4, 2, |
| 368 |
6, 2, 0, 2, 0, 2, 4, 2, 6, 0, 2, 4, 0, 2, 0, 2, 4, 2, |
| 369 |
4, 6, 0, 2, 0, 4, 2, 0, 4, 2, 4, 6, 2, 4, 2, 0, 2, 4, |
| 370 |
2, 4, 2, 4, 2, 4, 2, 4, 6, 2, 0, 2, 4, 2, 4, 2, 4, 6, |
| 371 |
2, 0, 2, 0, 4, 2, 4, 2, 4, 6, 2, 0, 2, 4, 2, 4, 2, 6, |
| 372 |
2, 0, 2, 4, 2, 4, 2, 6, 0, 4, 2, 4, 6, 0, 2, 4, 2, 4, |
| 373 |
2, 4, 2, 0, 2, 0, 2, 0, 4, 2, 0, 2, 0, 1, 0, 2, 4, 2, |
| 374 |
0, 4, 2, 1, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 0, |
| 375 |
2, 0, 2, 0, 2, 0, 2, 0, 14, 0, 17, 0, 17, 0, 17, 0, 16, 0, |
| 376 |
17, 0, 17, 0, 17, 0, 16, 0, 16, 0, 16, 0, 17, 0, 17, 0, 18, 0, |
| 377 |
16, 0, 16, 0, 19, 0, 16, 0, 16, 0, 16, 0, 16, 0, 16, 0, 17, 0, |
| 378 |
16, 0, 17, 0, 17, 0, 17, 0, 16, 0, 16, 0, 16, 0, 16, 0, 17, 0, |
| 379 |
16, 0, 16, 0, 17, 0, 17, 0, 16, 0, 16, 0, 16, 0, 16, 0, 16, 0, |
| 380 |
16, 0, 16, 0, 16, 0, 16, 0, 1, 2 |
| 381 |
], |
| 382 |
true); |
| 383 |
} |
| 384 |
return /** @type {number} */ ( |
| 385 |
goog.i18n.GraphemeBreak.inversions_.at(codePoint)); |
| 386 |
} |
| 387 |
}; |
| 388 |
|
| 389 |
/** |
| 390 |
* Extracts a code point from a string at the specified index. |
| 391 |
* |
| 392 |
* @param {string} str |
| 393 |
* @param {number} index |
| 394 |
* @return {number} Extracted code point. |
| 395 |
* @private |
| 396 |
*/ |
| 397 |
goog.i18n.GraphemeBreak.getCodePoint_ = function(str, index) { |
| 398 |
var codePoint = goog.i18n.uChar.getCodePointAround(str, index); |
| 399 |
return (codePoint < 0) ? -codePoint : codePoint; |
| 400 |
}; |
| 401 |
|
| 402 |
/** |
| 403 |
* Indicates if there is a grapheme cluster boundary between a and b. |
| 404 |
* |
| 405 |
* Legacy function. Does not cover cases where a sequence of code points is |
| 406 |
* required in order to decide if there is a grapheme cluster boundary, such as |
| 407 |
* emoji modifier sequences and emoji flag sequences. To cover all cases please |
| 408 |
* use {@code hasGraphemeBreakStrings}. |
| 409 |
* |
| 410 |
* There are two kinds of grapheme clusters: 1) Legacy 2) Extended. This method |
| 411 |
* is to check for both using a boolean flag to switch between them. If no flag |
| 412 |
* is provided rules for the extended clusters will be used by default. |
| 413 |
* |
| 414 |
* @param {number} a The code point value of the first character. |
| 415 |
* @param {number} b The code point value of the second character. |
| 416 |
* @param {boolean=} opt_extended If true, indicates extended grapheme cluster; |
| 417 |
* If false, indicates legacy cluster. Default value is true. |
| 418 |
* @return {boolean} True if there is a grapheme cluster boundary between |
| 419 |
* a and b; False otherwise. |
| 420 |
*/ |
| 421 |
goog.i18n.GraphemeBreak.hasGraphemeBreak = function(a, b, opt_extended) { |
| 422 |
return goog.i18n.GraphemeBreak.applyBreakRules_(a, b, opt_extended !== false); |
| 423 |
}; |
| 424 |
|
| 425 |
/** |
| 426 |
* Indicates if there is a grapheme cluster boundary between a and b. |
| 427 |
* |
| 428 |
* There are two kinds of grapheme clusters: 1) Legacy 2) Extended. This method |
| 429 |
* is to check for both using a boolean flag to switch between them. If no flag |
| 430 |
* is provided rules for the extended clusters will be used by default. |
| 431 |
* |
| 432 |
* @param {string} a String with the first sequence of characters. |
| 433 |
* @param {string} b String with the second sequence of characters. |
| 434 |
* @param {boolean=} opt_extended If true, indicates extended grapheme cluster; |
| 435 |
* If false, indicates legacy cluster. Default value is true. |
| 436 |
* @return {boolean} True if there is a grapheme cluster boundary between |
| 437 |
* a and b; False otherwise. |
| 438 |
*/ |
| 439 |
goog.i18n.GraphemeBreak.hasGraphemeBreakStrings = function(a, b, opt_extended) { |
| 440 |
goog.asserts.assert(goog.isDef(a), 'First string should be defined.'); |
| 441 |
goog.asserts.assert(goog.isDef(b), 'Second string should be defined.'); |
| 442 |
|
| 443 |
// Break if any of the strings is empty. |
| 444 |
if (a.length === 0 || b.length === 0) { |
| 445 |
return true; |
| 446 |
} |
| 447 |
|
| 448 |
return goog.i18n.GraphemeBreak.applyBreakRules_(a, b, opt_extended !== false); |
| 449 |
}; |