Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Russian not fixed completely #1

Open
DirectX opened this issue Feb 10, 2011 · 1 comment
Open

Russian not fixed completely #1

DirectX opened this issue Feb 10, 2011 · 1 comment

Comments

@DirectX
Copy link

DirectX commented Feb 10, 2011

NSString+Hyphenate.m
...
111: char const* tokenChars = [[token lowercaseString] UTF8String];
112: wordLength = strlen(tokenChars)]; // <-- Doubles length on multybyte words!
...

NSMakeRange(loc, wordLength - loc) below crashes due to
'*** -[NSCFString substringWithRange:]: Range or index out of bounds'.

Correcly: wordLength = [token length];

@xfyre
Copy link

xfyre commented Aug 13, 2011

Here's the patch to make hyphenation work correctly for Russian and get rid of NSRangeException:

--- NSString+Hyphenate.m        2011-01-19 17:17:51.000000000 +0300
+++ /Users/xfire/Documents/works/dvp/iphone/rbc/Classes/NSString+Hyphenate/NSString+Hyphenate.m 2011-08-13 19:12:55.000000000 +0400
@@ -11,7 +11,7 @@

 @implementation NSString (Hyphenate)

-- (NSString*)stringByHyphenatingWithLocale:(NSLocale*)locale {
+- (NSString *) stringByHyphenatingWithLocale:(NSLocale*)locale {
     static HyphenDict* dict = NULL;
     static NSString* localeIdentifier = nil;
     static NSBundle* bundle = nil;
@@ -123,7 +123,7 @@

             NSUInteger loc = 0;
             NSUInteger len = 0;
-            for (i = 0; i < wordLength; i++) {
+            for (i = 0; i < tokenRange.length; i++) {
                 if (hyphens[i] & 1) {
                     len = i - loc + 1;
                     [result appendString:
@@ -134,7 +134,7 @@
             }
             if (loc < wordLength) {
                 [result appendString:
-                 [token substringWithRange:NSMakeRange(loc, wordLength - loc)]];
+                 [token substringWithRange:NSMakeRange(loc, tokenRange.length - loc)]];
             }

             // Clean up

Enjoy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants