Changeset 30
 Timestamp:
 Dec 12, 2006, 8:32:18 PM (18 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

Include/Classes/System/String.ab
r1 r30 1 1 Class String 2 m_Chars As LPSTR 3 m_Length As Long 2 4 Public 3 Chars As LPSTR4 Length As Long5 5 6 6 Sub String() 7 Chars = _System_calloc(1)8 Length = 07 m_Chars = _System_calloc(1) 8 m_Length = 0 9 9 End Sub 10 10 … … 13 13 Assign(initStr) 14 14 End Sub 15 /* 16 Sub String(ByRef initStr As String)15 16 /* Sub String(ByRef initStr As String) 17 17 String() 18 18 Assign(initStr) … … 29 29 30 30 Sub ~String() 31 _System_free( Chars)32 Chars = 031 _System_free(m_Chars) 32 m_Chars = 0 33 33 #ifdef _DEBUG 34 Length = 034 m_Length = 0 35 35 #endif 36 36 End Sub 37 37 38 Function Chars() As LPSTR 39 Return m_Chars 40 End Function 41 42 Function Length() As Long 43 Return m_Length 44 End Function 45 38 46 Function Operator() As LPSTR 39 Return Chars47 Return m_Chars 40 48 End Function 41 49 42 50 Sub Operator = (ByRef objString As String) 43 Assign(objString. Chars, objString.Length)51 Assign(objString.m_Chars, objString.m_Length) 44 52 End Sub 45 53 … … 49 57 50 58 Function Operator[] (n As Long) As Byte 51 Return Chars[n]59 Return m_Chars[n] 52 60 End Function 53 61 54 62 Sub Operator[]= (n As Long, c As Byte) 55 Chars[n] = c63 m_Chars[n] = c 56 64 End Sub 57 65 … … 61 69 62 70 Function Operator+ (ByRef objString As String) As String 63 Return Concat(objString, objString. Length)71 Return Concat(objString, objString.m_Length) 64 72 End Function 65 73 … … 165 173 166 174 Function StrPtr() As LPSTR 167 Return Chars175 Return m_Chars 168 176 End Function 169 177 170 178 Sub ReSize(allocLength As Long) 171 179 If allocLength < 0 Then Exit Sub 172 If allocLength > Length Then180 If allocLength > m_Length Then 173 181 Dim oldLength As Long 174 oldLength = Length182 oldLength = m_Length 175 183 If AllocStringBuffer(allocLength) <> 0 Then 176 ZeroMemory( Chars + oldLength,Length  oldLength + 1)184 ZeroMemory(m_Chars + oldLength, m_Length  oldLength + 1) 177 185 End If 178 186 Else 179 Length = allocLength180 Chars[Length] = 0187 m_Length = allocLength 188 m_Chars[m_Length] = 0 181 189 End If 182 190 End Sub … … 185 193 If allocLength < 0 Then 186 194 Exit Sub 187 ElseIf allocLength > Length Then195 ElseIf allocLength > m_Length Then 188 196 Dim oldLength As Long 189 oldLength = Length197 oldLength = m_Length 190 198 If AllocStringBuffer(allocLength) <> 0 Then 191 FillMemory( Chars + oldLength,Length  oldLength, c)199 FillMemory(m_Chars + oldLength, m_Length  oldLength, c) 192 200 End If 193 201 Else 194 Length = allocLength195 End If 196 Chars[Length] = 0202 m_Length = allocLength 203 End If 204 m_Chars[m_Length] = 0 197 205 End Sub 198 206 199 207 Sub Assign(lpszText As LPSTR, textLength As Long) 200 If lpszText = Chars Then Exit Sub208 If lpszText = m_Chars Then Exit Sub 201 209 If AllocStringBuffer(textLength) <> 0 Then 202 memcpy( Chars, lpszText, textLength)203 Chars[Length] = 0210 memcpy(m_Chars, lpszText, textLength) 211 m_Chars[m_Length] = 0 204 212 End If 205 213 End Sub 206 214 207 215 Sub Assign(ByRef objString As String) 208 Assign(objString. Chars, objString.Length)216 Assign(objString.m_Chars, objString.m_Length) 209 217 End Sub 210 218 … … 213 221 Assign(lpszText, lstrlen(lpszText)) 214 222 Else 215 ' Chars=_System_realloc(Chars,1)216 Chars[0] = 0217 Length = 0223 'm_Chars=_System_realloc(m_Chars,1) 224 m_Chars[0] = 0 225 m_Length = 0 218 226 End If 219 227 End Sub … … 221 229 Sub Append(lpszText As LPSTR, textLength As Long) 222 230 Dim prevLen As Long 223 prevLen = Length224 If AllocStringBuffer( Length + textLength) <> 0 Then225 memcpy( Chars + prevLen, lpszText, textLength)226 Chars[Length] = 0231 prevLen = m_Length 232 If AllocStringBuffer(m_Length + textLength) <> 0 Then 233 memcpy(m_Chars + prevLen, lpszText, textLength) 234 m_Chars[m_Length] = 0 227 235 End If 228 236 End Sub … … 233 241 234 242 Sub Append(ByRef str As String) 235 Append(str. Chars, str.Length)243 Append(str.m_Chars, str.m_Length) 236 244 End Sub 237 245 … … 239 247 Dim tempString As String 240 248 With tempString 241 .AllocStringBuffer(This. Length + textLength)242 memcpy(. Chars, This.Chars, This.Length)243 memcpy(. Chars + This.Length, lpszText, textLength)244 . Chars[.Length] = 0249 .AllocStringBuffer(This.m_Length + textLength) 250 memcpy(.m_Chars, This.m_Chars, This.m_Length) 251 memcpy(.m_Chars + This.m_Length, lpszText, textLength) 252 .m_Chars[.m_Length] = 0 245 253 End With 246 254 Return tempString … … 248 256 249 257 Function Contains(ByRef objString As String) As BOOL 250 If IndexOf(objString, 0, Length) >= 0 Then258 If IndexOf(objString, 0, m_Length) >= 0 Then 251 259 Return _System_TRUE 252 260 Else … … 256 264 257 265 Function Contains(lpszText As LPSTR) As BOOL 258 If IndexOf(lpszText, 0, Length) >= 0 Then266 If IndexOf(lpszText, 0, m_Length) >= 0 Then 259 267 Return _System_TRUE 260 268 Else … … 264 272 265 273 Function IndexOf(lpszText As LPSTR) As Long 266 Return IndexOf(lpszText, 0, Length)274 Return IndexOf(lpszText, 0, m_Length) 267 275 End Function 268 276 269 277 Function IndexOf(lpszText As LPSTR, startIndex As Long) As Long 270 Return IndexOf(lpszText, startIndex, Length  startIndex)278 Return IndexOf(lpszText, startIndex, m_Length  startIndex) 271 279 End Function 272 280 … … 276 284 277 285 If startIndex < 0 Then Return 1 278 If count < 1 Or count + startIndex > Length Then Return 1279 If length > Length Then Return 1286 If count < 1 Or count + startIndex > m_Length Then Return 1 287 If length > m_Length Then Return 1 280 288 281 289 If length = 0 Then Return startIndex … … 284 292 For i = startIndex To startIndex + count  1 285 293 For j = 0 To length  1 286 If Chars[i + j] = lpszText[j] Then294 If m_Chars[i + j] = lpszText[j] Then 287 295 If j = length  1 Then Return i 288 296 Else … … 295 303 296 304 Function LastIndexOf(lpszText As LPSTR) As Long 297 Return LastIndexOf(lpszText, Length  1,Length)305 Return LastIndexOf(lpszText, m_Length  1, m_Length) 298 306 End Function 299 307 … … 306 314 length = lstrlen(lpszText) 307 315 308 If startIndex < 0 Or startIndex > Length  1 Then Return 1316 If startIndex < 0 Or startIndex > m_Length  1 Then Return 1 309 317 If count < 1 Or count > startIndex + 2 Then Return 1 310 If length > Length Then Return 1318 If length > m_Length Then Return 1 311 319 312 320 If length = 0 Then Return startIndex … … 315 323 For i = startIndex To startIndex  count + 1 Step 1 316 324 For j = length  1 To 0 Step 1 317 If Chars[i + j] = lpszText[j] Then325 If m_Chars[i + j] = lpszText[j] Then 318 326 If j = 0 Then Return i 319 327 Else … … 334 342 335 343 Function EndsWith(lpszText As LPSTR) As BOOL 336 If LastIndexOf(lpszText) = Length  lstrlen(lpszText) Then344 If LastIndexOf(lpszText) = m_Length  lstrlen(lpszText) Then 337 345 Return _System_TRUE 338 346 Else … … 345 353 length = lstrlen(lpszText) 346 354 347 If startIndex < 0 Or startIndex > Length Then Return 1355 If startIndex < 0 Or startIndex > m_Length Then Return 1 348 356 349 357 Dim newChars As LPSTR 350 newChars = _System_malloc(length + Length + 1)358 newChars = _System_malloc(length + m_Length + 1) 351 359 If newChars = 0 Then Return 1 352 360 353 memcpy(newChars, Chars, startIndex)361 memcpy(newChars, m_Chars, startIndex) 354 362 memcpy(newChars + startIndex, lpszText, length) 355 memcpy(newChars + startIndex + length, Chars + startIndex,Length  startIndex + 1)356 357 _System_free( Chars)358 Chars = newChars359 Length = length +Length360 Return Length363 memcpy(newChars + startIndex + length, m_Chars + startIndex, m_Length  startIndex + 1) 364 365 _System_free(m_Chars) 366 m_Chars = newChars 367 m_Length = length + m_Length 368 Return m_Length 361 369 End Function 362 370 363 371 Function SubString(startIndex As Long) As String 364 Return SubString(startIndex, Length  startIndex)372 Return SubString(startIndex, m_Length  startIndex) 365 373 End Function 366 374 367 375 Function SubString(startIndex As Long, length As Long) As String 368 376 If startIndex < 0 Or length <= 0 Then Return "" 369 If startIndex + length > Length Then Return ""377 If startIndex + length > m_Length Then Return "" 370 378 371 379 Dim temp As String 372 380 temp.AllocStringBuffer(length) 373 memcpy(temp. Chars, VarPtr(Chars[startIndex]), length)374 Chars[Length] = 0381 memcpy(temp.m_Chars, VarPtr(m_Chars[startIndex]), length) 382 m_Chars[m_Length] = 0 375 383 Return temp 376 384 End Function 377 385 378 386 Function Remove(startIndex As Long) As Long 379 If startIndex < 0 Or startIndex > Length Then Return 1380 Chars[startIndex] = 0381 Length = startIndex382 Return Length387 If startIndex < 0 Or startIndex > m_Length Then Return 1 388 m_Chars[startIndex] = 0 389 m_Length = startIndex 390 Return m_Length 383 391 End Function 384 392 385 393 Function Remove(startIndex As Long, count As Long) As Long 386 394 If startIndex < 0 Or count < 0 Then Return 1 387 If startIndex + count > Length Then Return 1395 If startIndex + count > m_Length Then Return 1 388 396 389 397 Dim newChars As LPSTR 390 newChars = _System_malloc( Length  count + 1)398 newChars = _System_malloc(m_Length  count + 1) 391 399 If newChars = 0 Then Return 1 392 400 393 memcpy(newChars, Chars, startIndex)394 memcpy(newChars + startIndex, Chars + startIndex + count,Length  startIndex  count)395 newChars[ Length  count] = 0396 397 _System_free( Chars)398 Chars = newChars399 Length =Length  count400 Return Length401 memcpy(newChars, m_Chars, startIndex) 402 memcpy(newChars + startIndex, m_Chars + startIndex + count, m_Length  startIndex  count) 403 newChars[m_Length  count] = 0 404 405 _System_free(m_Chars) 406 m_Chars = newChars 407 m_Length = m_Length  count 408 Return m_Length 401 409 End Function 402 410 403 411 Function IsNullOrEmpty() As BOOL 404 If Length = 0 Then412 If m_Length = 0 Then 405 413 Return _System_TRUE 406 414 Else … … 411 419 Sub Replace(oldChar As Byte, newChar As Byte) 412 420 Dim i As Long 413 For i = 0 To ELM( Length)414 If Chars[i] = oldChar Then415 Chars[i] = newChar421 For i = 0 To ELM(m_Length) 422 If m_Chars[i] = oldChar Then 423 m_Chars[i] = newChar 416 424 End If 417 425 Next … … 419 427 420 428 Sub Replace(ByRef oldStr As String, ByRef newStr As String) 421 Replace(oldStr, oldStr. Length, newStr, newStr.Length)429 Replace(oldStr, oldStr.m_Length, newStr, newStr.m_Length) 422 430 End Sub 423 431 … … 436 444 Exit Do 437 445 End If 438 .Append( Chars + current, pos  current)446 .Append(m_Chars + current, pos  current) 439 447 .Append(newStr, newLen) 440 448 current = pos + oldLen 441 449 Loop 442 .Append( Chars + current,Length  current)450 .Append(m_Chars + current, m_Length  current) 443 451 End With 444 452 Swap(tempString) … … 446 454 447 455 Sub ToLower() 448 CharLower( Chars)456 CharLower(m_Chars) 449 457 End Sub 450 458 451 459 Sub ToUpper() 452 CharUpper( Chars)460 CharUpper(m_Chars) 453 461 End Sub 454 462 … … 456 464 Dim tempLen As Long 457 465 Dim tempChars As PSTR 458 tempLen = x. Length459 tempChars = x. Chars460 x. Length = This.Length461 x. Chars = This.Chars462 This. Length = tempLen463 This. Chars = tempChars466 tempLen = x.m_Length 467 tempChars = x.m_Chars 468 x.m_Length = This.m_Length 469 x.m_Chars = This.m_Chars 470 This.m_Length = tempLen 471 This.m_Chars = tempChars 464 472 End Sub 465 473 … … 469 477 If textLength < 0 Then 470 478 Return 0 471 ElseIf textLength > Length Then472 AllocStringBuffer = _System_realloc( Chars, textLength + 1)479 ElseIf textLength > m_Length Then 480 AllocStringBuffer = _System_realloc(m_Chars, textLength + 1) 473 481 If AllocStringBuffer <> 0 Then 474 Length = textLength475 Chars = AllocStringBuffer482 m_Length = textLength 483 m_Chars = AllocStringBuffer 476 484 End If 477 485 Else 478 Length = textLength479 AllocStringBuffer = Chars486 m_Length = textLength 487 AllocStringBuffer = m_Chars 480 488 End If 481 489 End Function
Note:
See TracChangeset
for help on using the changeset viewer.