@@ -2035,20 +2035,43 @@ String String::reversed() const
20352035 if (numChars <= 0 )
20362036 return *this ;
20372037
2038- HeapBlock<CharPointerType> positions (numChars);
2038+ auto isCombiningMark = [](yup_wchar c)
2039+ {
2040+ // Combining Diacritical Marks
2041+ if (c >= 0x0300 && c <= 0x036F ) return true ;
2042+ // Combining Diacritical Marks Extended
2043+ if (c >= 0x1AB0 && c <= 0x1AFF ) return true ;
2044+ // Combining Diacritical Marks Supplement
2045+ if (c >= 0x1DC0 && c <= 0x1DFF ) return true ;
2046+ // Combining Half Marks
2047+ if (c >= 0xFE20 && c <= 0xFE2F ) return true ;
2048+ // Combining Diacritical Marks for Symbols
2049+ if (c >= 0x20D0 && c <= 0x20FF ) return true ;
2050+ return false ;
2051+ };
20392052
2040- StringCreationHelper builder (text);
2053+ std::vector<String> clusters;
2054+ clusters.reserve (numChars);
2055+
2056+ for (int i = 0 ; i < numChars; ++i)
2057+ {
2058+ String cluster = substring (i, i + 1 );
20412059
2042- int index = 0 ;
2043- for (auto it = text; ! it.isEmpty () && index < numChars; ++it, ++index)
2044- positions[index] = it;
2060+ while (i + 1 < numChars && isCombiningMark ((*this )[i + 1 ]))
2061+ {
2062+ ++i;
2063+ cluster += substring (i, i + 1 );
2064+ }
20452065
2046- for ( int i = index - 1 ; i >= 0 ; --i)
2047- builder. write (*positions[i]);
2066+ clusters. emplace_back ( std::move (cluster));
2067+ }
20482068
2049- builder.write (0 ); // null terminator
2069+ String result;
2070+ result.preallocateBytes (numChars);
2071+ for (auto it = clusters.rbegin (); it != clusters.rend (); ++it)
2072+ result += *it;
20502073
2051- return String ( std::move (builder. result )) ;
2074+ return result;
20522075}
20532076
20542077String String::formattedRaw (const char * pf, ...)
0 commit comments