Revert "Updated Strings unit with new functions"
This reverts commit 5cb415c76b898143ddcc4ea63d600254b2cc30e4.
This commit is contained in:
parent
5cb415c76b
commit
7588a4c9cb
@ -16,7 +16,6 @@
|
||||
Include->Strings - String Manipulation.
|
||||
|
||||
@author(Kieron Morris <kjm@kieronmorris.me>)
|
||||
@author(Aaron Hance <ah@aaronhance.me>)
|
||||
}
|
||||
unit strings;
|
||||
|
||||
@ -34,10 +33,6 @@ function stringCopy(str : pchar) : pchar;
|
||||
function stringNew(size : uint32) : pchar;
|
||||
function stringSize(str : pchar) : uint32;
|
||||
function stringConcat(str1, str2 : pchar) : pchar;
|
||||
function stringTrim(str : pchar; size : utnt32) : pchar;
|
||||
function stringSub(str : pchar; start, size : uint32) : pchar;
|
||||
function stringReplace(str, find, replace : pchar) : pchar;
|
||||
function stringIndexOf(str, find : pchar) : int32;
|
||||
function stringContains(str : pchar; sub : pchar) : boolean;
|
||||
function stringToInt(str : pchar) : uint32;
|
||||
function hexStringToInt(str : pchar) : uint32;
|
||||
@ -156,94 +151,6 @@ begin
|
||||
stringConcat:= result;
|
||||
end;
|
||||
|
||||
// Trim the string to the specified length.
|
||||
function stringTrim(str : pchar; length : uInt32) : pchar;
|
||||
var
|
||||
result : pchar;
|
||||
begin
|
||||
result:= stringNew(size);
|
||||
memcpy(uint32(str), uint32(result), size);
|
||||
stringShrink:= result;
|
||||
end;
|
||||
|
||||
// Return a substring of the string.
|
||||
function stringSub(str : pchar; start, size : uint32) : pchar;
|
||||
var
|
||||
result : pchar;
|
||||
begin
|
||||
result:= stringNew(size);
|
||||
memcpy(uint32(str)+start, uint32(result), size);
|
||||
stringSub:= result;
|
||||
end;
|
||||
|
||||
// Replace first instance of a string with another.
|
||||
function stringReplace(str, find, replace : pchar) : pchar;
|
||||
var
|
||||
result : pchar;
|
||||
i, j, k : uint32;
|
||||
found : boolean;
|
||||
begin
|
||||
|
||||
// Find the first instance of the find string.
|
||||
i:= 0;
|
||||
found:= false;
|
||||
while (i < stringSize(str)) and (not found) do begin
|
||||
if stringEquals(str+i, find) then begin
|
||||
found:= true;
|
||||
end else begin
|
||||
inc(i);
|
||||
end;
|
||||
end;
|
||||
|
||||
// If we found the find string, replace it.
|
||||
if found then begin
|
||||
result:= stringNew(stringSize(str) - stringSize(find) + stringSize(replace));
|
||||
j:= 0;
|
||||
k:= 0;
|
||||
while i < stringSize(str) do begin
|
||||
if stringEquals(str+i, find) then begin
|
||||
memcpy(uint32(replace), uint32(result+j), stringSize(replace));
|
||||
j:= j + stringSize(replace);
|
||||
inc(i, stringSize(find));
|
||||
end else begin
|
||||
result[j]:= str[i];
|
||||
inc(j);
|
||||
inc(i);
|
||||
end;
|
||||
end;
|
||||
stringReplace:= result;
|
||||
end else begin
|
||||
stringReplace:= stringCopy(str);
|
||||
end;
|
||||
|
||||
// Return the result.
|
||||
stringReplace:= result;
|
||||
|
||||
end;
|
||||
|
||||
|
||||
// Find the index of the first instance of a string.
|
||||
function stringIndexOf(str, find : pchar) : int32;
|
||||
var
|
||||
i : uint32;
|
||||
found : boolean;
|
||||
begin
|
||||
i:= 0;
|
||||
found:= false;
|
||||
while (i < stringSize(str)) and (not found) do begin
|
||||
if stringEquals(str+i, find) then begin
|
||||
found:= true;
|
||||
end else begin
|
||||
inc(i);
|
||||
end;
|
||||
end;
|
||||
if found then begin
|
||||
stringIndexOf:= i;
|
||||
end else begin
|
||||
stringIndexOf:= -1;
|
||||
end;
|
||||
end;
|
||||
|
||||
function stringContains(str : pchar; sub : pchar) : boolean;
|
||||
var
|
||||
strEnd, subEnd, i, j, count : uint32;
|
||||
|
Loading…
x
Reference in New Issue
Block a user