Revision: 4978
          http://skim-app.svn.sourceforge.net/skim-app/?rev=4978&view=rev
Author:   hofman
Date:     2008-11-21 17:58:52 +0000 (Fri, 21 Nov 2008)

Log Message:
-----------
Combine repetitive code in macro

Modified Paths:
--------------
    trunk/NSString_SKExtensions.m

Modified: trunk/NSString_SKExtensions.m
===================================================================
--- trunk/NSString_SKExtensions.m       2008-11-21 15:29:19 UTC (rev 4977)
+++ trunk/NSString_SKExtensions.m       2008-11-21 17:58:52 UTC (rev 4978)
@@ -174,6 +174,10 @@
     return ((character >= 0xDC00UL) && (character <= 0xDFFFUL) ? true : false);
 }
 
+static inline bool __SKIsSurrogateCharacter(const UniChar character) {
+    return ((character >= 0xD800UL) && (character <= 0xDFFFUL) ? true : false);
+}
+
 static inline UTF32Char __SKGetLongCharacterForSurrogatePair(const UniChar 
surrogateHigh, const UniChar surrogateLow) {
     return ((surrogateHigh - 0xD800UL) << 10) + (surrogateLow - 0xDC00UL) + 
0x0010000UL;
 }
@@ -185,9 +189,6 @@
             (ch >= 0x100000UL && ch <= 0x10FFFFUL)); /* supplementary private 
use B */
 }
 
-#define SURROGATE_START 0xD800
-#define SURROGATE_END 0xDFFF
-
 // Remove anything in the private use planes, and/or malformed surrogate pair 
sequences rdar://problem/6273932
 - (NSString *)stringByRemovingAliens {
 
@@ -201,16 +202,15 @@
     CFStringInitInlineBuffer(theString, &inlineBuffer, CFRangeMake(0, length));
     UniChar ch;
     
-#define LAZY_COPY do{if((void*)self==theString){theString=(void*)[[self 
mutableCopyWithZone:[self zone]] autorelease];}} while(0)
+#define DELETE_CHARACTERS(n) 
do{if((void*)self==theString){theString=(void*)[[self mutableCopyWithZone:[self 
zone]] autorelease];};CFStringDelete(theString, CFRangeMake(delIdx, n));} 
while(0)
         
     // idx is current index into the inline buffer, and delIdx is current 
index in the mutable string
     CFIndex idx = 0, delIdx = 0;
     while(idx < length){
         ch = CFStringGetCharacterFromInlineBuffer(&inlineBuffer, idx);
         if (__SKIsPrivateUseCharacter(ch)) {
-            LAZY_COPY;
-            CFStringDelete(theString, CFRangeMake(delIdx, 1));
-        } else if ((ch >= SURROGATE_START) && (ch <= SURROGATE_END)) {
+            DELETE_CHARACTERS(1);
+        } else if (__SKIsSurrogateCharacter(ch)) {
             
             if ((idx + 1) < length) {
                 
@@ -219,13 +219,11 @@
                 UTF32Char longChar = 
__SKGetLongCharacterForSurrogatePair(highChar, lowChar);
                 // if we only have half of a surrogate pair, delete the 
offending character
                 if (__SKIsSurrogateLowCharacter(lowChar) == false || 
__SKIsSurrogateHighCharacter(highChar) == false) {
-                    LAZY_COPY;
-                    CFStringDelete(theString, CFRangeMake(delIdx, 1));
+                    DELETE_CHARACTERS(1);
                     // only deleted a single char, so don't need to adjust idx
                 } else if (__SKIsPrivateUseCharacter(longChar)) {
-                    LAZY_COPY;
                     // remove the pair; can't display private use characters
-                    CFStringDelete(theString, CFRangeMake(delIdx, 2));
+                    DELETE_CHARACTERS(2);
                     // adjust since we removed two characters...
                     idx++;
                 } else {
@@ -236,8 +234,7 @@
                 
             } else {
                 // insufficient length for this to be a valid sequence, so 
it's only half of a surrogate pair
-                LAZY_COPY;
-                CFStringDelete(theString, CFRangeMake(delIdx, 1));
+                DELETE_CHARACTERS(1);
             }
             
         } else {


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to