40 #ifndef _stringtool_cpp
41 #define _stringtool_cpp
43 #include "stringtool.h"
63 if( Hex.size() != 2 ) {
69 Converter << std::hex << Hex;
81 Converter << std::hex << static_cast<Mezzanine::UInt8>( Channel * 255.0 );
84 if( Ret.size() == 1 ) {
99 {
return ( ToCheck >=
'0' && ToCheck <=
'9' ); }
102 {
return ( ToCheck >=
'a' && ToCheck <=
'z' ); }
105 {
return ( ToCheck >=
'A' && ToCheck <=
'Z' ); }
111 {
return ( ToCheck >=
'a' && ToCheck <=
'f' ); }
114 {
return ( ToCheck >=
'A' && ToCheck <=
'F' ); }
130 const String Delims =
" \t\r";
133 while( Forward < Source.size() )
135 if( Delims.find( Source[Forward] ) == String::npos ) {
140 Source.erase(0,Forward);
143 Whole Reverse = Source.size();
146 if( Delims.find( Source[Reverse-1] ) == String::npos ) {
151 Source.erase(Reverse);
158 Ret.reserve( MaxSplits ? MaxSplits + 1 : 10 );
165 Pos = Source.find_first_of(Delims,Start);
168 }
else if( Pos == String::npos || ( MaxSplits && Splits == MaxSplits ) ) {
169 Ret.push_back(Source.substr(Start));
172 Ret.push_back(Source.substr(Start,Pos - Start));
175 Start = Source.find_first_not_of(Delims,Start);
177 }
while(Pos != String::npos);
184 std::transform(Source.begin(),Source.end(),Source.begin(),::toupper);
195 std::transform(Source.begin(),Source.end(),Source.begin(),::tolower);
206 Boole PrevCharIsLetter =
false;
207 for( String::iterator CurrIt = Source.begin() ; CurrIt != Source.end() ; ++CurrIt )
211 if( !PrevCharIsLetter && CurrCharIsLowerLetter ) {
213 }
else if( PrevCharIsLetter && CurrCharIsUpperLetter ) {
216 PrevCharIsLetter = CurrCharIsLowerLetter || CurrCharIsUpperLetter;
229 size_t StrLen = Str.length();
230 size_t PatternLen = Pattern.length();
231 String Start = Str.substr(0,PatternLen);
233 if( CaseSensitive ) {
234 return ( Start == Pattern );
237 if( PatternLen > StrLen || PatternLen == 0 ) {
241 String LowerPattern = Pattern;
244 return (Start == LowerPattern);
249 size_t StrLen = Str.length();
250 size_t PatternLen = Pattern.length();
251 String End = Str.substr(StrLen - PatternLen,PatternLen);
253 if( CaseSensitive ) {
254 return ( End == Pattern );
257 if( PatternLen > StrLen || PatternLen == 0 ) {
261 String LowerPattern = Pattern;
264 return ( End == LowerPattern );
269 for(
size_t CurrIndex = Source.find_first_of(
" ") ; CurrIndex != String::npos ; CurrIndex = Source.find_first_of(
" ",CurrIndex) )
271 size_t EndIndex = CurrIndex;
272 while( Source[EndIndex] ==
' ' ) EndIndex++;
273 Source.replace(CurrIndex,EndIndex-CurrIndex,
" ");
284 if( 2 == Digits.size() ) {
294 converter << ToConvert.
X <<
" " << ToConvert.
Y;
295 return converter.str();
301 if( 3 == Digits.size() ) {
311 converter << ToConvert.
X <<
" " << ToConvert.
Y <<
" " << ToConvert.
Z;
312 return converter.str();
318 if( 4 == Digits.size() ) {
328 converter << ToConvert.
X <<
" " << ToConvert.
Y <<
" " << ToConvert.
Z <<
" " << ToConvert.
W;
329 return converter.str();
335 if( 4 == Digits.size() ) {
346 return converter.str();
351 if( ToConvert.size() < 6 ) {
356 Ret.
RedChannel = ConvertHexToColourChannel( ToConvert.substr(0,2) );
357 Ret.
GreenChannel = ConvertHexToColourChannel( ToConvert.substr(2,2) );
358 Ret.
BlueChannel = ConvertHexToColourChannel( ToConvert.substr(4,2) );
361 else Ret.
AlphaChannel = ConvertHexToColourChannel( ToConvert.substr(6,2) );
369 Ret.append( ConvertColourChannelToHex(ToConvert.
RedChannel) );
370 Ret.append( ConvertColourChannelToHex(ToConvert.
GreenChannel) );
371 Ret.append( ConvertColourChannelToHex(ToConvert.
BlueChannel) );
372 Ret.append( ConvertColourChannelToHex(ToConvert.
AlphaChannel) );
381 String StrCopy = ToConvert;
383 if(
"true" == StrCopy)
return true;
384 else if(
"yes" == StrCopy)
return true;
385 else if(
"1" == StrCopy)
return true;
386 else if(
"false" == StrCopy)
return false;
387 else if(
"no" == StrCopy)
return false;
388 else if(
"0" == StrCopy)
return false;
469 case Input::KEY_A:
return ( ShiftPressed ?
"A" :
"a" );
break;
470 case Input::KEY_B:
return ( ShiftPressed ?
"B" :
"b" );
break;
471 case Input::KEY_C:
return ( ShiftPressed ?
"C" :
"c" );
break;
472 case Input::KEY_D:
return ( ShiftPressed ?
"D" :
"d" );
break;
473 case Input::KEY_E:
return ( ShiftPressed ?
"E" :
"e" );
break;
474 case Input::KEY_F:
return ( ShiftPressed ?
"F" :
"f" );
break;
475 case Input::KEY_G:
return ( ShiftPressed ?
"G" :
"g" );
break;
476 case Input::KEY_H:
return ( ShiftPressed ?
"H" :
"h" );
break;
477 case Input::KEY_I:
return ( ShiftPressed ?
"I" :
"i" );
break;
478 case Input::KEY_J:
return ( ShiftPressed ?
"J" :
"j" );
break;
479 case Input::KEY_K:
return ( ShiftPressed ?
"K" :
"k" );
break;
480 case Input::KEY_L:
return ( ShiftPressed ?
"L" :
"l" );
break;
481 case Input::KEY_M:
return ( ShiftPressed ?
"M" :
"m" );
break;
482 case Input::KEY_N:
return ( ShiftPressed ?
"N" :
"n" );
break;
483 case Input::KEY_O:
return ( ShiftPressed ?
"O" :
"o" );
break;
484 case Input::KEY_P:
return ( ShiftPressed ?
"P" :
"p" );
break;
485 case Input::KEY_Q:
return ( ShiftPressed ?
"Q" :
"q" );
break;
486 case Input::KEY_R:
return ( ShiftPressed ?
"R" :
"r" );
break;
487 case Input::KEY_S:
return ( ShiftPressed ?
"S" :
"s" );
break;
488 case Input::KEY_T:
return ( ShiftPressed ?
"T" :
"t" );
break;
489 case Input::KEY_U:
return ( ShiftPressed ?
"U" :
"u" );
break;
490 case Input::KEY_V:
return ( ShiftPressed ?
"V" :
"v" );
break;
491 case Input::KEY_W:
return ( ShiftPressed ?
"W" :
"w" );
break;
492 case Input::KEY_X:
return ( ShiftPressed ?
"X" :
"x" );
break;
493 case Input::KEY_Y:
return ( ShiftPressed ?
"Y" :
"y" );
break;
494 case Input::KEY_Z:
return ( ShiftPressed ?
"Z" :
"z" );
break;
495 case Input::KEY_1:
return ( ShiftPressed ?
"!" :
"1" );
break;
496 case Input::KEY_2:
return ( ShiftPressed ?
"@" :
"2" );
break;
497 case Input::KEY_3:
return ( ShiftPressed ?
"#" :
"3" );
break;
498 case Input::KEY_4:
return ( ShiftPressed ?
"$" :
"4" );
break;
499 case Input::KEY_5:
return ( ShiftPressed ?
"%" :
"5" );
break;
500 case Input::KEY_6:
return ( ShiftPressed ?
"^" :
"6" );
break;
501 case Input::KEY_7:
return ( ShiftPressed ?
"&" :
"7" );
break;
502 case Input::KEY_8:
return ( ShiftPressed ?
"*" :
"8" );
break;
503 case Input::KEY_9:
return ( ShiftPressed ?
"(" :
"9" );
break;
504 case Input::KEY_0:
return ( ShiftPressed ?
")" :
"0" );
break;
505 case Input::KEY_MINUS:
return ( ShiftPressed ?
"_" :
"-" );
break;
506 case Input::KEY_EQUALS:
return ( ShiftPressed ?
"+" :
"=" );
break;
507 case Input::KEY_LEFTBRACKET:
return ( ShiftPressed ?
"{" :
"[" );
break;
508 case Input::KEY_RIGHTBRACKET:
return ( ShiftPressed ?
"}" :
"]" );
break;
510 case Input::KEY_SEMICOLON:
return ( ShiftPressed ?
":" :
";" );
break;
511 case Input::KEY_APOSTROPHE:
return ( ShiftPressed ?
"\"" :
"'" );
break;
513 case Input::KEY_COMMA:
return ( ShiftPressed ?
"<" :
"," );
break;
514 case Input::KEY_PERIOD:
return ( ShiftPressed ?
">" :
"." );
break;
515 case Input::KEY_SLASH:
return ( ShiftPressed ?
"?" :
"/" );
break;
516 case Input::KEY_KP_1:
return "1";
break;
517 case Input::KEY_KP_2:
return "2";
break;
518 case Input::KEY_KP_3:
return "3";
break;
519 case Input::KEY_KP_4:
return "4";
break;
520 case Input::KEY_KP_5:
return "5";
break;
521 case Input::KEY_KP_6:
return "6";
break;
522 case Input::KEY_KP_7:
return "7";
break;
523 case Input::KEY_KP_8:
return "8";
break;
524 case Input::KEY_KP_9:
return "9";
break;
525 case Input::KEY_KP_0:
return "0";
break;
526 case Input::KEY_KP_PERIOD:
return ".";
break;
527 default:
return "";
break;
int32_t Int32
An 32-bit integer.
std::vector< String > StringVector
This is a simple datatype for a vector container of strings.
bool Boole
Generally acts a single bit, true or false.
Real X
Coordinate on the X vector.
Real Z
Coordinate on the Z vector.
#define MEZZ_EXCEPTION(num, desc)
An easy way to throw exceptions with rich information.
int Integer
A datatype used to represent any integer close to.
Real Y
The Y component of the Axis.
uint8_t UInt8
An 8-bit unsigned integer.
This is a simple class for holding 4 reals representing the colour any give object or lightsource can...
This implements the exception hiearchy for Mezzanine.
std::stringstream StringStream
A Datatype used for streaming operations with strings.
float Real
A Datatype used to represent a real floating point number.
char Char8
A datatype to represent one character.
uint16_t UInt16
An 16-bit unsigned integer.
Real GreenChannel
Value from 0.0 to 1.0 representing the amount of green present in the colour. 1.0 if very green...
Real Y
Coordinate on the Y vector.
Real X
Coordinate on the X vector.
Real W
Rotation on the Axis X, Y and Z defined.
uint32_t UInt32
An 32-bit unsigned integer.
This is used to represent a point on a 2 dimentional area, such as a screen.
Real AlphaChannel
Value from 0.0 to 1.0 representing the transparency of the colours. 1.0 is opaque and 0...
Real Y
Coordinate on the Y vector.
int16_t Int16
An 16-bit integer.
Thrown when parameters are checked at runtime and found invalid.
This is used to represent a point in space, or a vector through space.
The bulk of the engine components go in this namspace.
unsigned long Whole
Whole is an unsigned integer, it will be at least 32bits in size.
Real BlueChannel
Value from 0.0 to 1.0 representing the amount of blue present in the colour. 1.0 if very blue...
Real RedChannel
Value from 0.0 to 1.0 representing the amount of red present in the colour. 1.0 if very red...
Real X
The X component of the Axis.
This is used to store information about rotation in 3d space.
int8_t Int8
An 8-bit integer.
Real Z
The Z component of the Axis.
std::string String
A datatype used to a series of characters.