Changes in Include/Classes/System/String.ab [30:1]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Include/Classes/System/String.ab
r30 r1 1 1 Class String 2 m_Chars As LPSTR3 m_Length As Long4 2 Public 3 Chars As LPSTR 4 Length As Long 5 5 6 6 Sub String() 7 m_Chars = _System_calloc(1)8 m_Length = 07 Chars = _System_calloc(1) 8 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( m_Chars)32 m_Chars = 031 _System_free(Chars) 32 Chars = 0 33 33 #ifdef _DEBUG 34 m_Length = 034 Length = 0 35 35 #endif 36 36 End Sub 37 37 38 Function Chars() As LPSTR39 Return m_Chars40 End Function41 42 Function Length() As Long43 Return m_Length44 End Function45 46 38 Function Operator() As LPSTR 47 Return m_Chars39 Return Chars 48 40 End Function 49 41 50 42 Sub Operator = (ByRef objString As String) 51 Assign(objString. m_Chars, objString.m_Length)43 Assign(objString.Chars, objString.Length) 52 44 End Sub 53 45 … … 57 49 58 50 Function Operator[] (n As Long) As Byte 59 Return m_Chars[n]51 Return Chars[n] 60 52 End Function 61 53 62 54 Sub Operator[]= (n As Long, c As Byte) 63 m_Chars[n] = c55 Chars[n] = c 64 56 End Sub 65 57 … … 69 61 70 62 Function Operator+ (ByRef objString As String) As String 71 Return Concat(objString, objString. m_Length)63 Return Concat(objString, objString.Length) 72 64 End Function 73 65 … … 173 165 174 166 Function StrPtr() As LPSTR 175 Return m_Chars167 Return Chars 176 168 End Function 177 169 178 170 Sub ReSize(allocLength As Long) 179 171 If allocLength < 0 Then Exit Sub 180 If allocLength > m_Length Then172 If allocLength > Length Then 181 173 Dim oldLength As Long 182 oldLength = m_Length174 oldLength = Length 183 175 If AllocStringBuffer(allocLength) <> 0 Then 184 ZeroMemory( m_Chars + oldLength, m_Length - oldLength + 1)176 ZeroMemory(Chars + oldLength, Length - oldLength + 1) 185 177 End If 186 178 Else 187 m_Length = allocLength188 m_Chars[m_Length] = 0179 Length = allocLength 180 Chars[Length] = 0 189 181 End If 190 182 End Sub … … 193 185 If allocLength < 0 Then 194 186 Exit Sub 195 ElseIf allocLength > m_Length Then187 ElseIf allocLength > Length Then 196 188 Dim oldLength As Long 197 oldLength = m_Length189 oldLength = Length 198 190 If AllocStringBuffer(allocLength) <> 0 Then 199 FillMemory( m_Chars + oldLength, m_Length - oldLength, c)191 FillMemory(Chars + oldLength, Length - oldLength, c) 200 192 End If 201 193 Else 202 m_Length = allocLength203 End If 204 m_Chars[m_Length] = 0194 Length = allocLength 195 End If 196 Chars[Length] = 0 205 197 End Sub 206 198 207 199 Sub Assign(lpszText As LPSTR, textLength As Long) 208 If lpszText = m_Chars Then Exit Sub200 If lpszText = Chars Then Exit Sub 209 201 If AllocStringBuffer(textLength) <> 0 Then 210 memcpy( m_Chars, lpszText, textLength)211 m_Chars[m_Length] = 0202 memcpy(Chars, lpszText, textLength) 203 Chars[Length] = 0 212 204 End If 213 205 End Sub 214 206 215 207 Sub Assign(ByRef objString As String) 216 Assign(objString. m_Chars, objString.m_Length)208 Assign(objString.Chars, objString.Length) 217 209 End Sub 218 210 … … 221 213 Assign(lpszText, lstrlen(lpszText)) 222 214 Else 223 ' m_Chars=_System_realloc(m_Chars,1)224 m_Chars[0] = 0225 m_Length = 0215 'Chars=_System_realloc(Chars,1) 216 Chars[0] = 0 217 Length = 0 226 218 End If 227 219 End Sub … … 229 221 Sub Append(lpszText As LPSTR, textLength As Long) 230 222 Dim prevLen As Long 231 prevLen = m_Length232 If AllocStringBuffer( m_Length + textLength) <> 0 Then233 memcpy( m_Chars + prevLen, lpszText, textLength)234 m_Chars[m_Length] = 0223 prevLen = Length 224 If AllocStringBuffer(Length + textLength) <> 0 Then 225 memcpy(Chars + prevLen, lpszText, textLength) 226 Chars[Length] = 0 235 227 End If 236 228 End Sub … … 241 233 242 234 Sub Append(ByRef str As String) 243 Append(str. m_Chars, str.m_Length)235 Append(str.Chars, str.Length) 244 236 End Sub 245 237 … … 247 239 Dim tempString As String 248 240 With tempString 249 .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] = 0241 .AllocStringBuffer(This.Length + textLength) 242 memcpy(.Chars, This.Chars, This.Length) 243 memcpy(.Chars + This.Length, lpszText, textLength) 244 .Chars[.Length] = 0 253 245 End With 254 246 Return tempString … … 256 248 257 249 Function Contains(ByRef objString As String) As BOOL 258 If IndexOf(objString, 0, m_Length) >= 0 Then250 If IndexOf(objString, 0, Length) >= 0 Then 259 251 Return _System_TRUE 260 252 Else … … 264 256 265 257 Function Contains(lpszText As LPSTR) As BOOL 266 If IndexOf(lpszText, 0, m_Length) >= 0 Then258 If IndexOf(lpszText, 0, Length) >= 0 Then 267 259 Return _System_TRUE 268 260 Else … … 272 264 273 265 Function IndexOf(lpszText As LPSTR) As Long 274 Return IndexOf(lpszText, 0, m_Length)266 Return IndexOf(lpszText, 0, Length) 275 267 End Function 276 268 277 269 Function IndexOf(lpszText As LPSTR, startIndex As Long) As Long 278 Return IndexOf(lpszText, startIndex, m_Length - startIndex)270 Return IndexOf(lpszText, startIndex, Length - startIndex) 279 271 End Function 280 272 … … 284 276 285 277 If startIndex < 0 Then Return -1 286 If count < 1 Or count + startIndex > m_Length Then Return -1287 If length > m_Length Then Return -1278 If count < 1 Or count + startIndex > Length Then Return -1 279 If length > Length Then Return -1 288 280 289 281 If length = 0 Then Return startIndex … … 292 284 For i = startIndex To startIndex + count - 1 293 285 For j = 0 To length - 1 294 If m_Chars[i + j] = lpszText[j] Then286 If Chars[i + j] = lpszText[j] Then 295 287 If j = length - 1 Then Return i 296 288 Else … … 303 295 304 296 Function LastIndexOf(lpszText As LPSTR) As Long 305 Return LastIndexOf(lpszText, m_Length - 1, m_Length)297 Return LastIndexOf(lpszText, Length - 1, Length) 306 298 End Function 307 299 … … 314 306 length = lstrlen(lpszText) 315 307 316 If startIndex < 0 Or startIndex > m_Length - 1 Then Return -1308 If startIndex < 0 Or startIndex > Length - 1 Then Return -1 317 309 If count < 1 Or count > startIndex + 2 Then Return -1 318 If length > m_Length Then Return -1310 If length > Length Then Return -1 319 311 320 312 If length = 0 Then Return startIndex … … 323 315 For i = startIndex To startIndex - count + 1 Step -1 324 316 For j = length - 1 To 0 Step -1 325 If m_Chars[i + j] = lpszText[j] Then317 If Chars[i + j] = lpszText[j] Then 326 318 If j = 0 Then Return i 327 319 Else … … 342 334 343 335 Function EndsWith(lpszText As LPSTR) As BOOL 344 If LastIndexOf(lpszText) = m_Length - lstrlen(lpszText) Then336 If LastIndexOf(lpszText) = Length - lstrlen(lpszText) Then 345 337 Return _System_TRUE 346 338 Else … … 353 345 length = lstrlen(lpszText) 354 346 355 If startIndex < 0 Or startIndex > m_Length Then Return -1347 If startIndex < 0 Or startIndex > Length Then Return -1 356 348 357 349 Dim newChars As LPSTR 358 newChars = _System_malloc(length + m_Length + 1)350 newChars = _System_malloc(length + Length + 1) 359 351 If newChars = 0 Then Return -1 360 352 361 memcpy(newChars, m_Chars, startIndex)353 memcpy(newChars, Chars, startIndex) 362 354 memcpy(newChars + startIndex, lpszText, length) 363 memcpy(newChars + startIndex + length, m_Chars + startIndex, m_Length - startIndex + 1)364 365 _System_free( m_Chars)366 m_Chars = newChars367 m_Length = length + m_Length368 Return m_Length355 memcpy(newChars + startIndex + length, Chars + startIndex, Length - startIndex + 1) 356 357 _System_free(Chars) 358 Chars = newChars 359 Length = length + Length 360 Return Length 369 361 End Function 370 362 371 363 Function SubString(startIndex As Long) As String 372 Return SubString(startIndex, m_Length - startIndex)364 Return SubString(startIndex, Length - startIndex) 373 365 End Function 374 366 375 367 Function SubString(startIndex As Long, length As Long) As String 376 368 If startIndex < 0 Or length <= 0 Then Return "" 377 If startIndex + length > m_Length Then Return ""369 If startIndex + length > Length Then Return "" 378 370 379 371 Dim temp As String 380 372 temp.AllocStringBuffer(length) 381 memcpy(temp. m_Chars, VarPtr(m_Chars[startIndex]), length)382 m_Chars[m_Length] = 0373 memcpy(temp.Chars, VarPtr(Chars[startIndex]), length) 374 Chars[Length] = 0 383 375 Return temp 384 376 End Function 385 377 386 378 Function Remove(startIndex As Long) As Long 387 If startIndex < 0 Or startIndex > m_Length Then Return -1388 m_Chars[startIndex] = 0389 m_Length = startIndex390 Return m_Length379 If startIndex < 0 Or startIndex > Length Then Return -1 380 Chars[startIndex] = 0 381 Length = startIndex 382 Return Length 391 383 End Function 392 384 393 385 Function Remove(startIndex As Long, count As Long) As Long 394 386 If startIndex < 0 Or count < 0 Then Return -1 395 If startIndex + count > m_Length Then Return -1387 If startIndex + count > Length Then Return -1 396 388 397 389 Dim newChars As LPSTR 398 newChars = _System_malloc( m_Length - count + 1)390 newChars = _System_malloc(Length - count + 1) 399 391 If newChars = 0 Then Return -1 400 392 401 memcpy(newChars, m_Chars, startIndex)402 memcpy(newChars + startIndex, m_Chars + startIndex + count, m_Length - startIndex - count)403 newChars[ m_Length - count] = 0404 405 _System_free( m_Chars)406 m_Chars = newChars407 m_Length = m_Length - count408 Return m_Length393 memcpy(newChars, Chars, startIndex) 394 memcpy(newChars + startIndex, Chars + startIndex + count, Length - startIndex - count) 395 newChars[Length - count] = 0 396 397 _System_free(Chars) 398 Chars = newChars 399 Length = Length - count 400 Return Length 409 401 End Function 410 402 411 403 Function IsNullOrEmpty() As BOOL 412 If m_Length = 0 Then404 If Length = 0 Then 413 405 Return _System_TRUE 414 406 Else … … 419 411 Sub Replace(oldChar As Byte, newChar As Byte) 420 412 Dim i As Long 421 For i = 0 To ELM( m_Length)422 If m_Chars[i] = oldChar Then423 m_Chars[i] = newChar413 For i = 0 To ELM(Length) 414 If Chars[i] = oldChar Then 415 Chars[i] = newChar 424 416 End If 425 417 Next … … 427 419 428 420 Sub Replace(ByRef oldStr As String, ByRef newStr As String) 429 Replace(oldStr, oldStr. m_Length, newStr, newStr.m_Length)421 Replace(oldStr, oldStr.Length, newStr, newStr.Length) 430 422 End Sub 431 423 … … 444 436 Exit Do 445 437 End If 446 .Append( m_Chars + current, pos - current)438 .Append(Chars + current, pos - current) 447 439 .Append(newStr, newLen) 448 440 current = pos + oldLen 449 441 Loop 450 .Append( m_Chars + current, m_Length - current)442 .Append(Chars + current, Length - current) 451 443 End With 452 444 Swap(tempString) … … 454 446 455 447 Sub ToLower() 456 CharLower( m_Chars)448 CharLower(Chars) 457 449 End Sub 458 450 459 451 Sub ToUpper() 460 CharUpper( m_Chars)452 CharUpper(Chars) 461 453 End Sub 462 454 … … 464 456 Dim tempLen As Long 465 457 Dim tempChars As PSTR 466 tempLen = x. m_Length467 tempChars = x. m_Chars468 x. m_Length = This.m_Length469 x. m_Chars = This.m_Chars470 This. m_Length = tempLen471 This. m_Chars = tempChars458 tempLen = x.Length 459 tempChars = x.Chars 460 x.Length = This.Length 461 x.Chars = This.Chars 462 This.Length = tempLen 463 This.Chars = tempChars 472 464 End Sub 473 465 … … 477 469 If textLength < 0 Then 478 470 Return 0 479 ElseIf textLength > m_Length Then480 AllocStringBuffer = _System_realloc( m_Chars, textLength + 1)471 ElseIf textLength > Length Then 472 AllocStringBuffer = _System_realloc(Chars, textLength + 1) 481 473 If AllocStringBuffer <> 0 Then 482 m_Length = textLength483 m_Chars = AllocStringBuffer474 Length = textLength 475 Chars = AllocStringBuffer 484 476 End If 485 477 Else 486 m_Length = textLength487 AllocStringBuffer = m_Chars478 Length = textLength 479 AllocStringBuffer = Chars 488 480 End If 489 481 End Function
Note:
See TracChangeset
for help on using the changeset viewer.