Do you want to use 8-bit strings on mobile platforms with all the nice old-fashioned features?
ORawByteString has been designed to make old code easily portable to mobile platforms – you only have to rename functions like “Copy” to “AnsiCopy”, that’s all.
With ORawByteString you can write code like this:
procedure TestAnsiString(const aOutputLines: TStrings); var Raw: RawByteString; Wide: string; I: Integer; C: PAnsiChar; begin Raw := RawByteString('HEADET'); Raw[AnsiLength(Raw)] := AnsiChar('R');//Raw = HEADER Wide := UTF8ToString(Raw);//convert "HEADER" from UTF-8 (ASCII) to UTF-16 aOutputLines.Clear; aOutputLines.Add(Wide);//output "HEADER" Raw := RawByteString(Wide);//CONVERT UTF-16 back into ASCII (without any codepage) I := Pos('H', Raw);//Fast search in RawByteString Raw := AnsiCopy(Raw, I, 3);//Use fast copy on RawByteString -> Raw = "HEA" Wide := String(Raw);//CONVERT ASCII to UTF-16 (without any codepage) C := PAnsiChar(Raw);//YOU CAN EVEN USE PAnsiChar!!! Raw := RawByteString(C);//AND convert PAnsiChar back to RawByteString/AnsiString C := PAnsiChar(Raw); aOutputLines.Add(String(C));//output "A" (the third letter from C (PAnsiChar is always 0-based) AnsiDelete(Raw, 1, 1);//Fast delete in RawByteString -> Raw = "EA" AnsiInsert(RawByteString('x'), Raw, 2);//Fast insert -> Raw = "ExA" Raw := UpperCase(Raw);//Fast uppercase -> Raw = "EXA" aOutputLines.Add(String(Raw));//output "EXA" Raw := LowerCase(Raw);//Fast uppercase -> Raw = "exa" aOutputLines.Add(String(Raw));//output "exa" end;
ORawByteString.pas allows you to:
- use 8-bit AnsiString and RawByteString on mobile platforms.
- use 8-bit PAnsiChar on mobile platforms.
- use 8-bit AnsiChar on mobile platforms.
- use the same AnsiString code on desktop and mobile.
- -> no IDE hacking is needed
It features it’s own text functions like AnsiInsert(), AnsiCopy(), AnsiDelete(), AnsiLength(), Pos(), LowerCase() etc. to offer maximum performance.
And when we talk about performance: ORawByteString is in some scenarios a little bit slower than string on mobile platforms, but most of the test cases and an usual usage showed no significant performance drawbacks. String operations perform on ORawByteString as fast as on string.
ORawByteString features full copy-on-write, mutability and all string features you have always taken advantage of.
On the one hand ORawByteString is a technical exhibition on how you can use records with operators to create your own delphi type, but on the other hand it can also be useful since it’s not certain that 8-bit strings will be officially available on mobile platforms at some point.
License: MPL 1.1 http://www.mozilla.org/MPL/1.1/