Changeset 5656 in orxonox.OLD for trunk/src/lib/util
- Timestamp:
- Nov 20, 2005, 9:45:28 PM (19 years ago)
- Location:
- trunk/src/lib/util
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/util/executor/executor.h
r5652 r5656 38 38 virtual Executor* clone () const = 0; 39 39 40 Executor* defaultValues(unsigned int count, va_list values); 40 41 Executor* defaultValues(unsigned int count, ...); 41 Executor* defaultValues(unsigned int count, va_list values);42 42 43 43 /** executes a Command @param object the object to apply this to @param parameters the parameters the command takes */ … … 56 56 57 57 void cloning(Executor* executor) const; 58 59 // const SubString& getSubString(const char* string) const { return SubString(string); }; 58 60 59 61 protected: … … 261 263 virtual void execute (BaseObject* object, const char* parameters) 262 264 { 263 SubString sub(parameters, ','); /// FIXME ///265 SubString sub(parameters, " \n\t,", '\\'); 264 266 //! FUNCTOR_LIST is the List of Executive Functions 265 267 #define FUNCTOR_LIST(x) ExecutorExecute ## x … … 323 325 virtual void execute (BaseObject* object, const char* parameters) 324 326 { 325 SubString sub(parameters, true);327 SubString sub(parameters, " \n\t,"); 326 328 //! FUNCTOR_LIST is the List of Executive Functions 327 329 #define FUNCTOR_LIST(x) ExecutorExecute ## x -
trunk/src/lib/util/substring.cc
r5209 r5656 123 123 assert (this->strings != NULL && this->offsets != NULL); 124 124 125 125 126 // split the String into substrings 126 127 int l = 0; … … 154 155 } 155 156 157 SubString::SubString(const char* string, const char* splitters, char escapeChar) 158 { 159 this->splittersCount = 0; 160 if (string == NULL || splitters == NULL) 161 { 162 this->strings = NULL; 163 this->offsets = NULL; 164 return; 165 } 166 167 // chop the input to the beginning of something usefull 168 if (strlen(string) > 0) 169 string = string + strspn(string, splitters); 170 171 // count the Splitters 172 bool lastWasSplitter = false; 173 for(unsigned int i = 0; i < strlen(string); i++) 174 { 175 176 if( strchr(splitters, string[i] )) 177 lastWasSplitter = true; 178 else 179 { 180 if (lastWasSplitter) 181 { 182 this->splittersCount ++; 183 lastWasSplitter = false; 184 } 185 } 186 } 187 this->splittersCount += 1; 188 189 // allocate memory 190 this->strings = new char*[this->splittersCount]; 191 this->offsets = new unsigned int[this->splittersCount]; 192 assert (this->strings != NULL && this->offsets != NULL); 193 194 195 // split the String into substrings 196 int l = 0; 197 unsigned int i = 0; 198 if( this->splittersCount > 1) 199 { 200 const char* offset = string; 201 const char* end = offset + strcspn(offset, splitters); 202 for (i = 0; i < this->splittersCount; i++) 203 { 204 assert( i < this->splittersCount); 205 l = end - offset; 206 this->strings[i] = new char[l + 1]; 207 assert( strings[i] != NULL); 208 strncpy( strings[i], offset, l); 209 strings[i][l] = '\0'; 210 this->offsets[i] = offset - string; 211 end += strspn(end, splitters); 212 offset = end; 213 end = offset + strcspn(offset, splitters); 214 } 215 } 216 else 217 { 218 unsigned int length = strcspn(string, splitters); 219 this->strings[0] = new char[length+1]; 220 strncpy(this->strings[0], string, length); 221 this->strings[0][length] = '\0'; 222 offsets[0] = 0; 223 } 224 } 225 226 156 227 /** 157 228 * removes the object from memory -
trunk/src/lib/util/substring.h
r5200 r5656 13 13 SubString(const char* string, char splitter = ','); 14 14 SubString(const char* string, bool whiteSpaces); 15 SubString(const char* string, const char* splitters, char escapeChar ='\\'); 15 16 ~SubString(); 16 17
Note: See TracChangeset
for help on using the changeset viewer.