]> err.no Git - scalable-opengroupware.org/blob - UI/SOGoUI/SOGoJSStringFormatter.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1134 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / SOGoUI / SOGoJSStringFormatter.m
1 /*
2   Copyright (C) 2000-2004 SKYRIX Software AG
3
4   This file is part of OGo
5
6   OGo is free software; you can redistribute it and/or modify it under
7   the terms of the GNU Lesser General Public License as published by the
8   Free Software Foundation; either version 2, or (at your option) any
9   later version.
10
11   OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12   WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14   License for more details.
15
16   You should have received a copy of the GNU Lesser General Public
17   License along with OGo; see the file COPYING.  If not, write to the
18   Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19   02111-1307, USA.
20 */
21 // $Id$
22
23
24 #import "SOGoJSStringFormatter.h"
25
26 @implementation SOGoJSStringFormatter
27
28 static NSCharacterSet *quotesSet = nil;
29 static NSCharacterSet *squoteSet = nil;
30 static NSCharacterSet *dquoteSet = nil;
31
32 + (void)initialize {
33   static BOOL didInit = NO;
34   
35   if(didInit)
36     return;
37   
38   didInit   = YES;
39   quotesSet = \
40     [[NSCharacterSet characterSetWithCharactersInString:@"'\""] retain];
41   squoteSet = \
42     [[NSCharacterSet characterSetWithCharactersInString:@"'"] retain];
43   dquoteSet = \
44     [[NSCharacterSet characterSetWithCharactersInString:@"\""] retain];
45 }
46
47 + (id)sharedFormatter {
48   static id sharedInstance = nil;
49   if(!sharedInstance) {
50     sharedInstance = [[self alloc] init];
51   }
52   return sharedInstance;
53 }
54
55 - (NSString *)stringByEscapingQuotesInString:(NSString *)_s {
56   return [_s stringByEscapingCharactersFromSet:quotesSet
57              usingStringEscaping:self];
58 }
59
60 - (NSString *)stringByEscapingSingleQuotesInString:(NSString *)_s {
61   return [_s stringByEscapingCharactersFromSet:squoteSet
62              usingStringEscaping:self];
63 }
64
65 - (NSString *)stringByEscapingDoubleQuotesInString:(NSString *)_s {
66   return [_s stringByEscapingCharactersFromSet:dquoteSet
67              usingStringEscaping:self];
68 }
69
70 - (NSString *)stringByEscapingString:(NSString *)_s {
71   if([_s isEqualToString:@"'"]) {
72     return @"'";
73   }
74   return @""";
75 }
76
77 @end