There is no spoon

Legacy:Nomad/WUtils

From Unreal Wiki, The Unreal Engine Documentation Site
Jump to: navigation, search

What is wUtils?

wString[edit]

InStrPlus()[edit]

static final function int InStrPlus( coerce string HayStack, coerce string Needle, optional int Start )
{
     local int i;
 
     for ( i = Start; i < Len( HayStack ); i++ )
          if ( Mid( HayStack, i, 1 ) == Needle )
               break;
 
     return i;
}

Mychaeel: I'm afraid this is a very slow and inefficient way to implement this function; besides, it'll only search for single-character "Needle"s. Better do something like InStrFrom on UT2003/Suggestions.

nomad: Your version is a lot better, this is something I used in Deus Ex ages ago.

ReplaceOption()[edit]

nomad: Not sure wheather or not this should be added to wUtils. It allows you to quickly change a value in the Options string used in Login and PostLogin.

static function bool ReplaceOption( out string Options, string Key, string NewValue, optional out string OldValue, optional bool bAddIfMissing )
{
     local array<string> OptionsArray< SEMI >
     local int i;
     local string   CurrentKey, CurrentValue;
     local bool     bReplaced;
     bReplaced = false;
 
     // Need to strip the first ? from Options otherwise Split doesn't work
     if ( Left( Options, 1 ) == "?" )
          Options = Right( Options, Len( Options ) - 1 );
 
     Split( Options, "?", OptionsArray );
 
     for ( i = 0; i < OptionsArray.Length; i++ ) {
          Divide( OptionsArray[i], "=", CurrentKey, CurrentValue );
 
          if ( CurrentKey ~= Key ) {
               OldValue = CurrentValue;
               OptionsArray[i] = CurrentKey$"="$NewValue;
               bReplaced = true;
               log( "ReplaceOption() :: Replaced ["$CurrentKey$"] Old = "$OldValue$", new = "$NewValue, 'wUtils' );
          }
     }
 
     if ( !bReplaced && bAddIfMissing )
          OptionsArray[OptionsArray.Length] = Key$"="$NewValue;
 
     Options = "?"$Join( OptionsArray, "?", Options );
     return bReplaced;
}