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 MySQL4 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.
26 #if LIB_FOUNDATION_BOEHM_GC
30 #import <objc/objc-api.h>
32 #import "NSString+MySQL4.h"
34 @implementation NSString(MySQL4MiscStrings)
36 - (NSString *)_mySQL4ModelMakeInstanceVarName {
41 if ([self length] == 0)
44 clen = [self cStringLength];
45 s = malloc(clen + 10);
47 [self getCString:s maxLength:clen];
49 for (cnt = cnt2 = 0; cnt < clen; cnt++, cnt2++) {
50 if ((s[cnt] == '_') && (s[cnt + 1] != '\0')) {
51 s[cnt2] = toupper(s[cnt + 1]);
54 else if ((s[cnt] == '2') && (s[cnt + 1] != '\0')) {
58 s[cnt2] = toupper(s[cnt]);
61 s[cnt2] = tolower(s[cnt]);
65 return [[[NSString alloc]
66 initWithCStringNoCopy:s length:strlen(s) freeWhenDone:YES]
70 - (NSString *)_mySQL4ModelMakeClassName {
75 if ([self length] == 0)
78 clen = [self cStringLength];
79 s = malloc(clen + 10);
81 [self getCString:s maxLength:clen];
83 for (cnt = cnt2 = 0; cnt < clen; cnt++, cnt2++) {
84 if ((s[cnt] == '_') && (s[cnt + 1] != '\0')) {
85 s[cnt2] = toupper(s[cnt + 1]);
88 else if ((s[cnt] == '2') && (s[cnt + 1] != '\0')) {
92 s[cnt2] = toupper(s[cnt]);
95 s[cnt2] = tolower(s[cnt]);
101 return [[[NSString alloc]
102 initWithCStringNoCopy:s length:strlen(s)
107 - (NSString *)_mySQL4StringWithCapitalizedFirstChar {
108 NSCharacterSet *upperSet;
109 NSMutableString *str;
111 if ([self length] == 0)
114 upperSet = [NSCharacterSet uppercaseLetterCharacterSet];
115 if ([upperSet characterIsMember:[self characterAtIndex:0]])
116 return [[self copy] autorelease];
118 str = [NSMutableString stringWithCapacity:[self length]];
119 [str appendString:[[self substringToIndex:1] uppercaseString]];
120 [str appendString:[self substringFromIndex:1]];
121 return [[str copy] autorelease];
124 - (NSString *)_mySQL4StripEndSpaces {
125 NSCharacterSet *spaceSet;
126 NSMutableString *str;
130 if ([self length] == 0)
131 return [[self copy] autorelease];
133 spaceSet = [NSCharacterSet whitespaceCharacterSet];
134 str = [NSMutableString stringWithCapacity:[self length]];
135 charAtIndex = [self methodForSelector:@selector(characterAtIndex:)];
138 for (range.location = ([self length] - 1);
140 range.location++, range.length++) {
143 c = (unichar)(int)charAtIndex(self, @selector(characterAtIndex:),
145 if (![spaceSet characterIsMember:c])
149 if (range.length > 0) {
150 [str appendString:self];
151 [str deleteCharactersInRange:range];
152 return [[str copy] autorelease];
154 return [[self copy] autorelease];
159 void __link_NSStringMySQL4() {
160 // used to force linking of object file
161 __link_NSStringMySQL4();