From bc6ee43ce67241b940cd99bfb731156767457a0f Mon Sep 17 00:00:00 2001 From: Matthias Andreas Benkard Date: Sun, 15 Jun 2008 11:36:14 +0200 Subject: MLKCharacter: Add methods for character case conversion. --- MLKCharacter.h | 13 +++++++++++-- MLKCharacter.m | 32 ++++++++++++++++++++++++++++++++ MLKReadtable.m | 13 +++++-------- 3 files changed, 48 insertions(+), 10 deletions(-) diff --git a/MLKCharacter.h b/MLKCharacter.h index 664803a..04049d4 100644 --- a/MLKCharacter.h +++ b/MLKCharacter.h @@ -26,7 +26,16 @@ unichar unichar; } --(MLKCharacter*) initWithUnichar:(unichar)anUnichar; +-(MLKCharacter *) initWithUnichar:(unichar)anUnichar; -+(MLKCharacter*) characterWithUnichar:(unichar)anUnichar; ++(MLKCharacter *) characterWithUnichar:(unichar)anUnichar; + +-(MLKCharacter *) uppercaseCharacter; +-(MLKCharacter *) lowercaseCharacter; + +-(unichar) uppercaseChar; +-(unichar) lowercaseChar; + ++(unichar) uppercaseCharForChar:(unichar)ch; ++(unichar) lowercaseCharForChar:(unichar)ch; @end diff --git a/MLKCharacter.m b/MLKCharacter.m index c653248..5daa22c 100644 --- a/MLKCharacter.m +++ b/MLKCharacter.m @@ -31,4 +31,36 @@ { return [[MLKCharacter alloc] initWithUnichar:anUnichar]; } + +-(MLKCharacter *) uppercaseCharacter +{ + return [MLKCharacter characterWithUnichar:[self uppercaseChar]]; +} + +-(MLKCharacter *) lowercaseCharacter +{ + return [MLKCharacter characterWithUnichar:[self lowercaseChar]]; +} + +-(unichar) uppercaseChar +{ + return [[[NSString stringWithFormat:@"%C", self->unichar] uppercaseString] + characterAtIndex:0]; +} + +-(unichar) lowercaseChar +{ + return [[[NSString stringWithFormat:@"%C", self->unichar] lowercaseString] + characterAtIndex:0]; +} + ++(unichar) uppercaseCharForChar:(unichar)ch +{ + return [[MLKCharacter characterWithUnichar:ch] uppercaseChar]; +} + ++(unichar) lowercaseCharForChar:(unichar)ch +{ + return [[MLKCharacter characterWithUnichar:ch] lowercaseChar]; +} @end diff --git a/MLKReadtable.m b/MLKReadtable.m index 59f6438..702a00b 100644 --- a/MLKReadtable.m +++ b/MLKReadtable.m @@ -17,6 +17,7 @@ */ #import "MLKReadtable.h" +#import "MLKCharacter.h" #import #import @@ -114,19 +115,15 @@ case MLKReadtableCase_PRESERVE: return ch; case MLKReadtableCase_UPCASE: - return [[[NSString stringWithFormat:@"%C", ch] uppercaseString] - characterAtIndex:0]; + return [MLKCharacter uppercaseCharForChar:ch]; case MLKReadtableCase_DOWNCASE: - return [[[NSString stringWithFormat:@"%C", ch] lowercaseString] - characterAtIndex:0]; + return [MLKCharacter lowercaseCharForChar:ch]; case MLKReadtableCase_INVERT: { unichar upCh; - upCh = [[[NSString stringWithFormat:@"%C", ch] uppercaseString] - characterAtIndex:0]; + upCh = [MLKCharacter uppercaseCharForChar:ch]; if (ch == upCh) - return [[[NSString stringWithFormat:@"%C", ch] lowercaseString] - characterAtIndex:0]; + return [MLKCharacter lowercaseCharForChar:ch]; else return upCh; } -- cgit v1.2.3