views:

211

answers:

3

Are there any wide-string manipulation implementations out there?

function WideUpperCase(const S: WideString): WideString;

function WidePos(Substr: WideString; S: WideString): Integer;

function StringReplaceW(const S, OldPattern, NewPattern: WideString; 
      Flags: TReplaceFlags): WideString;

etc
+2  A: 

The JEDI project includes JclUnicode.pas, which has WideUpperCase and WidePos, but not StringReplace. The SysUtils.pas StringReplace code isn't very complicated, so you could easily just copy that and replace string with WideString, AnsiPos with WidePos, and AnsiUpperCase with WideUpperCase and get something functional, if slow.

Craig Peterson
+1  A: 

The TntControls has a set of Wide-version functions.

stanleyxu2005
+1  A: 

I generally import the "Microsoft VBScript Regular Expression 5.5" type library and use IRegExp objects.

OP Edit

i like this answer, and i went ahead and wrote a StringReplaceW function using RegEx:

function StringReplaceW(const S, OldPattern, NewPattern: WideString; Flags: TReplaceFlags): WideString;
var
    objRegExp: OleVariant;
    Pattern: WideString;
    i: Integer;
begin
    {
        Convert the OldPattern string into a series of unicode points to match
        \uxxxx\uxxxx\uxxxx

            \uxxxx  Matches the ASCII character expressed by the UNICODE xxxx.
                        "\u00A3" matches "£".
    }
    Pattern := '';
    for i := 1 to Length(OldPattern) do
        Pattern := Pattern+'\u'+IntToHex(Ord(OldPattern[i]), 4);

    objRegExp := CreateOleObject('VBScript.RegExp');
    try
        objRegExp.Pattern := Pattern;
        objRegExp.IgnoreCase := (rfIgnoreCase in Flags);
        objRegExp.Global := (rfReplaceAll in Flags);

        Result := objRegExp.Replace(S, NewPattern);
    finally
        objRegExp := Null;
    end;
end;
Stijn Sanders