@@ -995,6 +995,50 @@ suite.test("Index encoding correction/UTF-8→16/conversions/UTF-16") {
995
995
}
996
996
#endif
997
997
998
+ suite. test ( " UTF-16 breadcrumbs " ) {
999
+
1000
+ let string = #"""
1001
+ The powerful programming language that is also easy to learn.
1002
+ 손쉽게 학습할 수 있는 강력한 프로그래밍 언어.
1003
+ 🪙 A 🥞 short 🍰 piece 🫘 of 🌰 text 👨👨👧👧 with 👨👩👦 some 🚶🏽 emoji 🇺🇸🇨🇦 characters 🧈
1004
+ some🔩times 🛺 placed 🎣 in 🥌 the 🆘 mid🔀dle 🇦🇶or🏁 around 🏳️🌈 a 🍇 w🍑o🥒r🥨d
1005
+ Unicode is such fun!
1006
+ U̷n̷i̷c̷o̴d̴e̷ ̶i̸s̷ ̸s̵u̵c̸h̷ ̸f̵u̷n̴!̵
1007
+ U̴̡̲͋̾n̵̻̳͌ì̶̠̕c̴̭̈͘ǫ̷̯͋̊d̸͖̩̈̈́ḛ̴́ ̴̟͎͐̈i̴̦̓s̴̜̱͘ ̶̲̮̚s̶̙̞͘u̵͕̯̎̽c̵̛͕̜̓h̶̘̍̽ ̸̜̞̿f̵̤̽ṷ̴͇̎͘ń̷͓̒!̷͍̾̚
1008
+ U̷̢̢̧̨̼̬̰̪͓̞̠͔̗̼̙͕͕̭̻̗̮̮̥̣͉̫͉̬̲̺͍̺͊̂ͅ\#
1009
+ n̶̨̢̨̯͓̹̝̲̣̖̞̼̺̬̤̝̊̌́̑̋̋͜͝ͅ\#
1010
+ ḭ̸̦̺̺͉̳͎́͑\#
1011
+ c̵̛̘̥̮̙̥̟̘̝͙̤̮͉͔̭̺̺̅̀̽̒̽̏̊̆͒͌̂͌̌̓̈́̐̔̿̂͑͠͝͝ͅ\#
1012
+ """#
1013
+
1014
+ print ( string. utf16. count)
1015
+ let indices = Array ( string. utf16. indices) + [ string. utf16. endIndex]
1016
+ for i in 0 ..< indices. count {
1017
+ for j in 0 ..< indices. count {
1018
+ // print(
1019
+ // """
1020
+ // i: \(i), indices[i]: \(indices[i]._description); \
1021
+ // j: \(j), indices[j]: \(indices[j]._description)
1022
+ // """)
1023
+
1024
+ let distance = string. utf16. distance ( from: indices [ i] , to: indices [ j] )
1025
+ expectEqual ( distance, j - i,
1026
+ """
1027
+ i: \( i) , indices[i]: \( indices [ i] . _description)
1028
+ j: \( j) , indices[j]: \( indices [ j] . _description)
1029
+ """ )
1030
+
1031
+ let target = string. utf16. index ( indices [ i] , offsetBy: j - i)
1032
+ expectEqual ( target, indices [ j] ,
1033
+ """
1034
+ i: \( i) , indices[i]: \( indices [ i] . _description)
1035
+ j: \( j) , indices[j]: \( indices [ j] . _description)
1036
+ target: \( target. _description)
1037
+ """ )
1038
+ }
1039
+ }
1040
+ }
1041
+
998
1042
suite. test ( " String.replaceSubrange index validation " )
999
1043
. forEach ( in: examples) { string in
1000
1044
guard #available( SwiftStdlib 5 . 7 , * ) else {
0 commit comments