40 #ifndef _stringtool_cpp
41 #define _stringtool_cpp
43 #include "stringtool.h"
44 #include "exception.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 ) {
98 static const String Delims =
" \t\r";
100 Source.erase(Source.find_last_not_of(Delims)+1);
102 Source.erase(0,Source.find_first_not_of(Delims));
108 Ret->reserve( MaxSplits ? MaxSplits+1 : 10 );
116 Pos = Source.find_first_of(Delims,Start);
121 else if(Pos == String::npos || (MaxSplits && Splits == MaxSplits))
123 Ret->push_back(Source.substr(Start));
128 Ret->push_back(Source.substr(Start,Pos - Start));
131 Start = Source.find_first_not_of(Delims,Start);
133 }
while(Pos != String::npos);
140 std::transform(Source.begin(),Source.end(),Source.begin(),::toupper);
145 std::transform(Source.begin(),Source.end(),Source.begin(),::tolower);
150 size_t StrLen = Str.length();
151 size_t PatternLen = Pattern.length();
153 if(PatternLen > StrLen || PatternLen == 0)
156 String Start = Str.substr(0,PatternLen);
160 String LowerPattern = Pattern;
163 return (Start == LowerPattern);
166 return (Start == Pattern);
171 size_t StrLen = Str.length();
172 size_t PatternLen = Pattern.length();
174 if(PatternLen > StrLen || PatternLen == 0)
177 String End = Str.substr(StrLen - PatternLen,PatternLen);
181 String LowerPattern = Pattern;
184 return (End == LowerPattern);
187 return (End == Pattern);
192 for(
size_t CurrIndex = Source.find_first_of(
" ") ; CurrIndex != String::npos ; CurrIndex = Source.find_first_of(
" ",CurrIndex) )
194 size_t EndIndex = CurrIndex;
195 while( Source[EndIndex] ==
' ' ) EndIndex++;
196 Source.replace(CurrIndex,EndIndex-CurrIndex,
" ");
207 if(2 == Digits->size())
217 std::stringstream converter;
218 converter << ToConvert.
X <<
" " << ToConvert.
Y;
219 return converter.str();
225 if(3 == Digits->size())
235 std::stringstream converter;
236 converter << ToConvert.
X <<
" " << ToConvert.
Y <<
" " << ToConvert.
Z;
237 return converter.str();
243 if(4 == Digits->size())
253 std::stringstream converter;
254 converter << ToConvert.
X <<
" " << ToConvert.
Y <<
" " << ToConvert.
Z <<
" " << ToConvert.
W;
255 return converter.str();
261 if(4 == Digits->size())
271 std::stringstream converter;
273 return converter.str();
278 if( ToConvert.size() < 6 ) {
283 Ret.
RedChannel = ConvertHexToColourChannel( ToConvert.substr(0,2) );
284 Ret.
GreenChannel = ConvertHexToColourChannel( ToConvert.substr(2,2) );
285 Ret.
BlueChannel = ConvertHexToColourChannel( ToConvert.substr(4,2) );
288 else Ret.
AlphaChannel = ConvertHexToColourChannel( ToConvert.substr(6,2) );
296 Ret.append( ConvertColourChannelToHex(ToConvert.
RedChannel) );
297 Ret.append( ConvertColourChannelToHex(ToConvert.
GreenChannel) );
298 Ret.append( ConvertColourChannelToHex(ToConvert.
BlueChannel) );
299 Ret.append( ConvertColourChannelToHex(ToConvert.
AlphaChannel) );
308 String StrCopy = ToConvert;
310 if(
"true" == StrCopy)
return true;
311 else if(
"yes" == StrCopy)
return true;
312 else if(
"1" == StrCopy)
return true;
313 else if(
"false" == StrCopy)
return false;
314 else if(
"no" == StrCopy)
return false;
315 else if(
"0" == StrCopy)
return false;
390 if(ShiftPressed)
return "A";
396 if(ShiftPressed)
return "B";
402 if(ShiftPressed)
return "C";
408 if(ShiftPressed)
return "D";
414 if(ShiftPressed)
return "E";
420 if(ShiftPressed)
return "F";
426 if(ShiftPressed)
return "G";
432 if(ShiftPressed)
return "H";
438 if(ShiftPressed)
return "I";
444 if(ShiftPressed)
return "J";
450 if(ShiftPressed)
return "K";
456 if(ShiftPressed)
return "L";
462 if(ShiftPressed)
return "M";
468 if(ShiftPressed)
return "N";
474 if(ShiftPressed)
return "O";
480 if(ShiftPressed)
return "P";
486 if(ShiftPressed)
return "Q";
492 if(ShiftPressed)
return "R";
498 if(ShiftPressed)
return "S";
504 if(ShiftPressed)
return "T";
510 if(ShiftPressed)
return "U";
516 if(ShiftPressed)
return "V";
522 if(ShiftPressed)
return "W";
528 if(ShiftPressed)
return "X";
534 if(ShiftPressed)
return "Y";
540 if(ShiftPressed)
return "Z";
546 if(ShiftPressed)
return "!";
552 if(ShiftPressed)
return "@";
558 if(ShiftPressed)
return "#";
564 if(ShiftPressed)
return "$";
570 if(ShiftPressed)
return "%";
576 if(ShiftPressed)
return "^";
582 if(ShiftPressed)
return "&";
588 if(ShiftPressed)
return "*";
594 if(ShiftPressed)
return "(";
600 if(ShiftPressed)
return ")";
604 case Input::KEY_MINUS:
606 if(ShiftPressed)
return "_";
610 case Input::KEY_EQUALS:
612 if(ShiftPressed)
return "+";
616 case Input::KEY_LEFTBRACKET:
618 if(ShiftPressed)
return "{";
622 case Input::KEY_RIGHTBRACKET:
624 if(ShiftPressed)
return "}";
630 if(ShiftPressed)
return "\\";
634 case Input::KEY_SEMICOLON:
636 if(ShiftPressed)
return ":";
640 case Input::KEY_APOSTROPHE:
642 if(ShiftPressed)
return "\"";
648 if(ShiftPressed)
return "~";
652 case Input::KEY_COMMA:
654 if(ShiftPressed)
return "<";
658 case Input::KEY_PERIOD:
660 if(ShiftPressed)
return ">";
664 case Input::KEY_SLASH:
666 if(ShiftPressed)
return "?";
670 case Input::KEY_KP_1:
675 case Input::KEY_KP_2:
680 case Input::KEY_KP_3:
685 case Input::KEY_KP_4:
690 case Input::KEY_KP_5:
695 case Input::KEY_KP_6:
700 case Input::KEY_KP_7:
705 case Input::KEY_KP_8:
710 case Input::KEY_KP_9:
715 case Input::KEY_KP_0:
720 case Input::KEY_KP_PERIOD: