4 Copyright (C) 1999 MDlink online service center GmbH and Helge Hess
6 Author: Helge Hess (helge@mdlink.de)
8 This file is part of the SQLite Adaptor Library
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Library General Public
12 License as published by the Free Software Foundation; either
13 version 2 of the License, or (at your option) any later version.
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Library General Public License for more details.
20 You should have received a copy of the GNU Library General Public
21 License along with this library; see the file COPYING.LIB.
22 If not, write to the Free Software Foundation,
23 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 // $Id: NSString+SQLite.m,v 1.1 2004/06/14 14:27:44 helge Exp $
27 #if LIB_FOUNDATION_BOEHM_GC
31 #import <objc/objc-api.h>
33 #import "NSString+SQLite.h"
35 @implementation NSString(SQLiteMiscStrings)
37 - (NSString *)_sqlite3ModelMakeInstanceVarName {
38 if ([self length] == 0)
45 clen = [self cStringLength];
46 s = malloc(clen + 10);
48 [self getCString:s maxLength:clen];
50 for (cnt = cnt2 = 0; cnt < clen; cnt++, cnt2++) {
51 if ((s[cnt] == '_') && (s[cnt + 1] != '\0')) {
52 s[cnt2] = toupper(s[cnt + 1]);
55 else if ((s[cnt] == '2') && (s[cnt + 1] != '\0')) {
59 s[cnt2] = toupper(s[cnt]);
62 s[cnt2] = tolower(s[cnt]);
66 return [[[NSString alloc]
67 initWithCStringNoCopy:s length:strlen(s) freeWhenDone:YES]
72 - (NSString *)_sqlite3ModelMakeClassName {
73 if ([self length] == 0)
80 clen = [self cStringLength];
81 s = malloc(clen + 10);
83 [self getCString:s maxLength:clen];
85 for (cnt = cnt2 = 0; cnt < clen; cnt++, cnt2++) {
86 if ((s[cnt] == '_') && (s[cnt + 1] != '\0')) {
87 s[cnt2] = toupper(s[cnt + 1]);
90 else if ((s[cnt] == '2') && (s[cnt + 1] != '\0')) {
94 s[cnt2] = toupper(s[cnt]);
97 s[cnt2] = tolower(s[cnt]);
101 s[0] = toupper(s[0]);
103 return [[[NSString alloc]
104 initWithCStringNoCopy:s length:strlen(s)
110 - (NSString *)_sqlite3StringWithCapitalizedFirstChar {
111 NSCharacterSet *upperSet = [NSCharacterSet uppercaseLetterCharacterSet];
113 if ([self length] == 0)
115 else if ([upperSet characterIsMember:[self characterAtIndex:0]])
116 return [[self copy] autorelease];
118 NSMutableString *str = [NSMutableString stringWithCapacity:[self length]];
120 [str appendString:[[self substringToIndex:1] uppercaseString]];
121 [str appendString:[self substringFromIndex:1]];
123 return [[str copy] autorelease];
127 - (NSString *)_sqlite3StripEndSpaces {
128 if ([self length] > 0) {
129 NSCharacterSet *spaceSet = [NSCharacterSet whitespaceCharacterSet];
130 NSMutableString *str = [NSMutableString stringWithCapacity:[self length]];
134 charAtIndex = [self methodForSelector:@selector(characterAtIndex:)];
137 for (range.location = ([self length] - 1);
139 range.location++, range.length++) {
142 c = (unichar)(int)charAtIndex(self, @selector(characterAtIndex:),
144 if (![spaceSet characterIsMember:c])
148 if (range.length > 0) {
149 [str appendString:self];
150 [str deleteCharactersInRange:range];
151 return AUTORELEASE([str copy]);
154 return AUTORELEASE([self copy]);
159 void __link_NSStringSQLite() {
160 // used to force linking of object file
161 __link_NSStringSQLite();