]> err.no Git - sope/commitdiff
generic escaping, minor refactoring
authorznek <znek@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Thu, 14 Oct 2004 20:11:56 +0000 (20:11 +0000)
committerznek <znek@e4a50df8-12e2-0310-a44c-efbce7f8a7e3>
Thu, 14 Oct 2004 20:11:56 +0000 (20:11 +0000)
git-svn-id: http://svn.opengroupware.org/SOPE/trunk@256 e4a50df8-12e2-0310-a44c-efbce7f8a7e3

sope-core/NGExtensions/ChangeLog
sope-core/NGExtensions/FdExt.subproj/GNUmakefile
sope-core/NGExtensions/FdExt.subproj/NSString+Escaping.m [new file with mode: 0644]
sope-core/NGExtensions/FdExt.subproj/NSString+misc.m
sope-core/NGExtensions/GNUmakefile
sope-core/NGExtensions/NGExtensions.xcode/project.pbxproj
sope-core/NGExtensions/NGExtensions/NGExtensions.h
sope-core/NGExtensions/NGExtensions/NSString+Escaping.h [new file with mode: 0644]
sope-core/NGExtensions/NGExtensions/NSString+misc.h
sope-core/NGExtensions/Version

index 57edda27028bc3b4ce6558844a1d468c28e4c9b7..751d7f5b8a58c391777a8b999b53d96896be2f60 100644 (file)
@@ -1,3 +1,14 @@
+2004-10-14  Marcus Mueller  <znek@mulle-kybernetik.com>
+
+       * v4.3.123
+
+       * FdExt.subproj/NSString+Escaping.m, NGExtensions/NSString+Escaping.h:
+         new category and protocol to do generic escaping. The category is
+         Unicode safe and optimized for performance.
+       
+       * FdExt.subproj/NSString+misc.m, NGExtensions/NSString+misc.h: moved
+         -stringByApplyingCEscaping to new NSString+Escaping.
+
 2004-10-11  Matthew Joyce  <mjoyce@aboveit.nl>
 
        * FdExt.subproj/NSCalendarDate+misc.m: fixed -isAfternoon (all dates
index b3930a15d75346c9549351292edffa0ed0c0ca1f..bfc4e16270afd7a8a3b086f0502060aeee96b163 100644 (file)
@@ -24,6 +24,7 @@ FdExt_OBJC_FILES = \
        NSSet+enumerator.m              \
        NSString+Ext.m                  \
        NSString+Encoding.m             \
+       NSString+Escaping.m             \
        NSString+Formatting.m           \
        NSString+misc.m                 \
        NSString+HTMLEscaping.m         \
diff --git a/sope-core/NGExtensions/FdExt.subproj/NSString+Escaping.m b/sope-core/NGExtensions/FdExt.subproj/NSString+Escaping.m
new file mode 100644 (file)
index 0000000..0ef980c
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+  Copyright (C) 2000-2004 SKYRIX Software AG
+
+  This file is part of OpenGroupware.org.
+
+  OGo is free software; you can redistribute it and/or modify it under
+  the terms of the GNU Lesser General Public License as published by the
+  Free Software Foundation; either version 2, or (at your option) any
+  later version.
+
+  OGo is distributed in the hope that it will be useful, but WITHOUT ANY
+  WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+  License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with OGo; see the file COPYING.  If not, write to the
+  Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+  02111-1307, USA.
+*/
+// $Id$
+
+
+#include <NGExtensions/NSString+Escaping.h>
+#include "common.h"
+
+@implementation NSString (Escaping)
+
+- (NSString *)stringByApplyingCEscaping {
+  // Unicode!
+  const char   *cstr;
+  char         *buffer;
+  register int pos = 0;
+  
+  cstr = [self cString];
+  buffer = malloc([self cStringLength] * 2 + 1);
+  
+  while (*cstr) {
+    switch (*cstr) {
+      case '\n':
+        buffer[pos] = '\\'; pos++;
+        buffer[pos] = 'n';
+        break;
+      case '\r':
+        buffer[pos] = '\\'; pos++;
+        buffer[pos] = 'r';
+        break;
+      case '\t':
+        buffer[pos] = '\\'; pos++;
+        buffer[pos] = 't';
+        break;
+        
+      default:
+        buffer[pos] = *cstr;
+        break;
+    }
+    cstr++;
+    pos++;
+  }
+  buffer[pos] = '\0';
+  
+#if NeXT_Foundation_LIBRARY || GNUSTEP_BASE_LIBRARY
+  {
+    NSString *s;
+    
+    s = buffer ? [NSString stringWithCString:buffer] : nil;
+    if (buffer) free(buffer);
+    return s;
+  }
+#else
+  return [NSString stringWithCStringNoCopy:buffer freeWhenDone:YES];
+#endif
+}
+
+- (NSString *)stringByEscapingCharactersFromSet:(NSCharacterSet *)_escSet
+  usingStringEscaping:(<NGStringEscaping>)_esc
+{
+  NSMutableString *safeString;
+  unsigned length;
+  NSRange prevRange, escRange;
+  BOOL needsEscaping;
+  
+  length    = [self length];
+  prevRange = NSMakeRange(0, length);
+  escRange  = [self rangeOfCharacterFromSet:_escSet options:0 range:prevRange];
+
+  needsEscaping = escRange.length > 0 ? YES : NO;
+  if (!needsEscaping) {
+    return self; /* cheap */
+  }
+  
+  safeString = [NSMutableString stringWithCapacity:length];
+  if (needsEscaping) {
+    NSRange todoRange;
+
+    length = prevRange.length;
+    do {
+      NSString *s;
+
+      prevRange.length = escRange.location - prevRange.location;
+      if (prevRange.length > 0)
+        [safeString appendString:[self substringWithRange:prevRange]];
+      s = [_esc stringByEscapingString:[self substringWithRange:escRange]];
+      if (s)
+        [safeString appendString:s];
+
+      prevRange.location = NSMaxRange(escRange);
+      todoRange.location = prevRange.location;
+      todoRange.length   = length - prevRange.location;
+      escRange           = [self rangeOfCharacterFromSet:_escSet
+                                 options:0
+                                 range:todoRange];
+    }
+    while(escRange.length > 0);
+    if(todoRange.length > 0) {
+      [safeString appendString:[self substringWithRange:todoRange]];
+    }
+  }
+  return safeString;
+}
+
+@end
index 0954939db9a4045eb544a3963805f35f58e3073b..190de2d10302ea022b5a8a2e501ccf19f3405b16 100644 (file)
 
 @implementation NSString(misc)
 
-- (NSString *)stringByApplyingCEscaping {
-  // Unicode!
-  const char   *cstr;
-  char         *buffer;
-  register int pos = 0;
-  
-  cstr = [self cString];
-  buffer = malloc([self cStringLength] * 2 + 1);
-    
-  while (*cstr) {
-    switch (*cstr) {
-      case '\n':
-        buffer[pos] = '\\'; pos++;
-        buffer[pos] = 'n';
-        break;
-      case '\r':
-        buffer[pos] = '\\'; pos++;
-        buffer[pos] = 'r';
-        break;
-      case '\t':
-        buffer[pos] = '\\'; pos++;
-        buffer[pos] = 't';
-        break;
-
-      default:
-        buffer[pos] = *cstr;
-        break;
-    }
-    cstr++;
-    pos++;
-  }
-  buffer[pos] = '\0';
-  
-#if NeXT_Foundation_LIBRARY || GNUSTEP_BASE_LIBRARY
-  {
-    NSString *s;
-    
-    s = buffer ? [NSString stringWithCString:buffer] : nil;
-    if (buffer) free(buffer);
-    return s;
-  }
-#else
-  return [NSString stringWithCStringNoCopy:buffer freeWhenDone:YES];
-#endif
-}
 - (NSSet *)bindingVariables
 {
   unsigned        len, pos = 0;
index ace564166be6d12511754f04bb439d11cb2a844e..e1c476bc969e4764cd3ebcf92f5971f9725458f1 100644 (file)
@@ -103,6 +103,7 @@ FdExt_HEADER_FILES = \
        NSString+German.h               \
        NSString+Formatting.h           \
        NSString+Encoding.h             \
+       NSString+Escaping.h             \
        NSString+misc.h                 \
        NSURL+misc.h                    \
        NGPropertyListParser.h          \
index e4d41e1271a29a8ff07b96f74d2d580f07abafef..ed18981bc910b4a33714372260978affc2080e5f 100644 (file)
                        settings = {
                        };
                };
+               AD665E37071F00AF00EC5911 = {
+                       fileEncoding = 5;
+                       indentWidth = 2;
+                       isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.h;
+                       path = "NSString+Escaping.h";
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               AD665E38071F00AF00EC5911 = {
+                       fileEncoding = 5;
+                       indentWidth = 2;
+                       isa = PBXFileReference;
+                       lastKnownFileType = sourcecode.c.objc;
+                       path = "NSString+Escaping.m";
+                       refType = 4;
+                       sourceTree = "<group>";
+               };
+               AD665E39071F00AF00EC5911 = {
+                       fileRef = AD665E37071F00AF00EC5911;
+                       isa = PBXBuildFile;
+                       settings = {
+                               ATTRIBUTES = (
+                                       Public,
+                               );
+                       };
+               };
+               AD665E3A071F00AF00EC5911 = {
+                       fileRef = AD665E38071F00AF00EC5911;
+                       isa = PBXBuildFile;
+                       settings = {
+                               COMPILER_FLAGS = "-I..";
+                       };
+               };
                ADD45B5E06FEF017004BBD65 = {
                        fileEncoding = 5;
                        indentWidth = 2;
                ADD65C6506DA3394007161CA = {
                        children = (
                                ADD65C4B06DA336E007161CA,
+                               AD665E38071F00AF00EC5911,
                                ADD65C4C06DA336E007161CA,
                                ADD65C4D06DA336E007161CA,
                                ADD65C4E06DA336E007161CA,
                                ADD65DE206DA3830007161CA,
                                ADD65DE306DA3830007161CA,
                                ADD65DE406DA3830007161CA,
+                               AD665E39071F00AF00EC5911,
                                ADD65DE506DA3830007161CA,
                                ADD65DE606DA3830007161CA,
                                ADD65DE706DA3830007161CA,
                                ADD65F3306DA397E007161CA,
                                ADD45B6106FEF017004BBD65,
                                AD4BF6EC070314EE006FB665,
+                               AD665E3A071F00AF00EC5911,
                        );
                        isa = PBXSourcesBuildPhase;
                        runOnlyForDeploymentPostprocessing = 0;
                        );
                        buildSettings = {
                                DYLIB_COMPATIBILITY_VERSION = 1;
-                               DYLIB_CURRENT_VERSION = 4.3.120;
+                               DYLIB_CURRENT_VERSION = 4.3.123;
                                FRAMEWORK_SEARCH_PATHS = "$(LOCAL_LIBRARY_DIR)/Frameworks";
                                FRAMEWORK_VERSION = A;
                                GCC_PRECOMPILE_PREFIX_HEADER = YES;
                };
                ADD65D6106DA382F007161CA = {
                        children = (
+                               ADD65D7D06DA382F007161CA,
+                               ADD65D7E06DA382F007161CA,
                                ADD65DF506DA38CA007161CA,
                                ADD65DEF06DA3877007161CA,
                                ADD65DEC06DA3848007161CA,
                                ADD65D7906DA382F007161CA,
                                ADD65D7B06DA382F007161CA,
                                ADD65D7C06DA382F007161CA,
-                               ADD65D7D06DA382F007161CA,
-                               ADD65D7E06DA382F007161CA,
                                ADD65D7F06DA382F007161CA,
                                ADD65D8006DA382F007161CA,
                                ADD65D8106DA382F007161CA,
                                ADD65D9E06DA3830007161CA,
                                ADD65D9F06DA3830007161CA,
                                ADD65DA006DA3830007161CA,
+                               AD665E37071F00AF00EC5911,
                                ADD65DA106DA3830007161CA,
                                ADD65DA206DA3830007161CA,
                                ADD65DA306DA3830007161CA,
index a52c195d8b7dbcff7cae67fb40e2a163a57a6d2f..79ebc1839f411e57c3092ea16cd7dd45dfda0f4a 100644 (file)
@@ -62,6 +62,7 @@
 #include <NGExtensions/NSSet+enumerator.h>
 #include <NGExtensions/NSString+Formatting.h>
 #include <NGExtensions/NSString+Encoding.h>
+#include <NGExtensions/NSString+Escaping.h>
 #include <NGExtensions/NSString+misc.h>
 #include <NGExtensions/NGObjectMacros.h>
 
diff --git a/sope-core/NGExtensions/NGExtensions/NSString+Escaping.h b/sope-core/NGExtensions/NGExtensions/NSString+Escaping.h
new file mode 100644 (file)
index 0000000..d0a95c2
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+  Copyright (C) 2000-2004 SKYRIX Software AG
+
+  This file is part of OpenGroupware.org.
+
+  OGo is free software; you can redistribute it and/or modify it under
+  the terms of the GNU Lesser General Public License as published by the
+  Free Software Foundation; either version 2, or (at your option) any
+  later version.
+
+  OGo is distributed in the hope that it will be useful, but WITHOUT ANY
+  WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+  License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with OGo; see the file COPYING.  If not, write to the
+  Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+  02111-1307, USA.
+*/
+// $Id$
+
+
+#ifndef        __NGExtensions_NSString_Escaping_H__
+#define        __NGExtensions_NSString_Escaping_H__
+
+#import <Foundation/NSString.h>
+
+@protocol NGStringEscaping < NSObject >
+- (NSString *)stringByEscapingString:(NSString *)_s;
+@end
+
+@interface NSString (Escaping)
+
+- (NSString *)stringByApplyingCEscaping;
+
+- (NSString *)stringByEscapingCharactersFromSet:(NSCharacterSet *)_set
+  usingStringEscaping:(<NGStringEscaping>)_esc;
+@end
+
+#endif /* __NGExtensions_NSString_Escaping_H__ */
index 0515ec7ee2ed1805d3d308731adc4cada31f2675..6ff0a8b2cdffb54779b2140a64eb135c2c45cd7c 100644 (file)
@@ -33,8 +33,6 @@
 
 @interface NSString(misc)
 
-- (NSString *)stringByApplyingCEscaping;
-
 /*
   Replaces keys, which enclosed in '$', with values from _bindings. The values
   are retrieved using the '-valueForStringBinding:' method which per default
index 754354e9aebe247d88eb554912929d37f001081e..902b0e2d7f67402171064fd8f24774d4086259fe 100644 (file)
@@ -1,6 +1,6 @@
 # version
 
-SUBMINOR_VERSION:=122
+SUBMINOR_VERSION:=123
 
 # v4.3.115 requires libFoundation v1.0.59
 # v4.2.72  requires libEOControl  v4.2.39