21 unit uUtils; |
21 unit uUtils; |
22 |
22 |
23 interface |
23 interface |
24 uses uTypes, uFloat; |
24 uses uTypes, uFloat; |
25 |
25 |
|
26 // returns s with whitespaces (chars <= #32) removed form both ends |
|
27 function Trim(s: shortstring) : shortstring; |
|
28 |
26 procedure SplitBySpace(var a, b: shortstring); |
29 procedure SplitBySpace(var a, b: shortstring); |
27 procedure SplitByChar(var a, b: shortstring; c: char); |
30 procedure SplitByChar(var a, b: shortstring; c: char); |
28 procedure SplitByCharA(var a, b: ansistring; c: char); |
31 procedure SplitByCharA(var a, b: ansistring; c: char); |
29 |
32 |
30 function EnumToStr(const en : TGearType) : shortstring; overload; |
33 function EnumToStr(const en : TGearType) : shortstring; overload; |
96 procedure initModule(isNotPreview: boolean); |
99 procedure initModule(isNotPreview: boolean); |
97 procedure freeModule; |
100 procedure freeModule; |
98 |
101 |
99 |
102 |
100 implementation |
103 implementation |
101 uses {$IFNDEF PAS2C}typinfo, {$ENDIF}Math, uConsts, uVariables, SysUtils, uPhysFSLayer, uDebug; |
104 uses {$IFNDEF PAS2C}typinfo, {$ENDIF}Math, uConsts, uVariables, uPhysFSLayer, uDebug; |
102 |
105 |
103 {$IFDEF DEBUGFILE} |
106 {$IFDEF DEBUGFILE} |
104 var logFile: PFSFile; |
107 var logFile: PFSFile; |
105 {$IFDEF USE_VIDEO_RECORDING} |
108 {$IFDEF USE_VIDEO_RECORDING} |
106 logMutex: TRTLCriticalSection; // mutex for debug file |
109 logMutex: TRTLCriticalSection; // mutex for debug file |
107 {$ENDIF} |
110 {$ENDIF} |
108 {$ENDIF} |
111 {$ENDIF} |
109 var CharArray: array[0..255] of Char; |
112 var CharArray: array[0..255] of Char; |
|
113 |
|
114 // All leading/tailing characters with ordinal values less than or equal to 32 (a space) are stripped. |
|
115 function Trim(s: shortstring) : shortstring; |
|
116 var len, left, right: integer; |
|
117 begin |
|
118 |
|
119 len:= Length(s); |
|
120 |
|
121 if len = 0 then |
|
122 exit(s); |
|
123 |
|
124 // find first non-whitespace |
|
125 left:= 1; |
|
126 while left <= len do |
|
127 begin |
|
128 if s[left] > #32 then |
|
129 break; |
|
130 inc(left); |
|
131 end; |
|
132 |
|
133 // find last non-whitespace |
|
134 right:= len; |
|
135 while right >= 1 do |
|
136 begin |
|
137 if s[right] > #32 then |
|
138 break; |
|
139 dec(right); |
|
140 end; |
|
141 |
|
142 // string is whitespace only |
|
143 if left > right then |
|
144 exit(''); |
|
145 |
|
146 // get string without surrounding whitespace |
|
147 len:= right - left + 1; |
|
148 |
|
149 Trim:= copy(s, left, len); |
|
150 |
|
151 end; |
110 |
152 |
111 procedure SplitBySpace(var a,b: shortstring); |
153 procedure SplitBySpace(var a,b: shortstring); |
112 begin |
154 begin |
113 SplitByChar(a,b,' '); |
155 SplitByChar(a,b,' '); |
114 end; |
156 end; |