summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Andreas Benkard <matthias@benkard.de>2008-06-15 11:36:14 +0200
committerMatthias Andreas Benkard <matthias@benkard.de>2008-06-15 11:36:14 +0200
commitbc6ee43ce67241b940cd99bfb731156767457a0f (patch)
tree362ce381ed464f5ca19e5a98931b1c3f6524fd5b
parent1395b759b4d1e62ec94ab756a6606ce7c2ed215f (diff)
MLKCharacter: Add methods for character case conversion.
-rw-r--r--MLKCharacter.h13
-rw-r--r--MLKCharacter.m32
-rw-r--r--MLKReadtable.m13
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 <Foundation/NSDictionary.h>
#import <Foundation/NSValue.h>
@@ -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;
}