int VAISNAVADAY::GetFestivalClass(TString &str) { int i, j, val; i = str.Find("[c"); if (i >= 0) { // i += 2; if ((i + 2) < str.GetLength()) { val = int(str.GetAt(i+2) - '0'); j = str.Find("]", i); if (j >= str.GetLength()) j = str.GetLength(); if (j > i) { str.Delete(i, j - i + 1); } if (val < 0 || val > 6) return -1; return val; } else return -1; } else { return -1; } }
//-------------------------------------------------------- // //-------------------------------------------------------- Bool TLString::ReadNextFloatArray(const TString& String,u32& CharIndex,float* pFloats,u32 FloatSize,Bool ReturnInvalidFloatZero) { // loop through parsing seperators and floats u32 FloatIndex = 0; while ( FloatIndex < FloatSize ) { // step over whitespace s32 NonWhitespaceIndex = String.GetCharIndexNonWhitespace( CharIndex ); // no more non-whitespace? no more floats then if ( NonWhitespaceIndex == -1 ) return FALSE; // move char past whitespace CharIndex = (u32)NonWhitespaceIndex; s32 NextComma = String.GetCharIndex(',', CharIndex); s32 NextWhitespace = String.GetCharIndexWhitespace( CharIndex ); s32 NextSplit = String.GetLength(); if ( NextComma != -1 && NextComma < NextSplit ) NextSplit = NextComma; if ( NextWhitespace != -1 && NextWhitespace < NextSplit ) NextSplit = NextWhitespace; // split TTempString Stringf; Stringf.Append( String, CharIndex, NextSplit-CharIndex ); if ( !Stringf.GetFloat( pFloats[FloatIndex] ) ) { // gr: this is a work around when processing floats but encounter invalid floats in strings... say 1.1e07 (invalid floats from outputter) if ( ReturnInvalidFloatZero ) { pFloats[FloatIndex] = 0.f; } else { TLDebug_Break("Failed to parse first float"); return FALSE; } } // next float FloatIndex++; // move string along past split CharIndex = NextSplit+1; // out of string if ( CharIndex >= String.GetLength() ) { CharIndex = String.GetLength(); break; } } return TRUE; }
static enum v7_err jsBotSay(struct v7 *v7, v7_val_t *res) { long argc = v7_argc(v7); if (argc == 0) { return V7_OK; } v7_val_t v = v7_arg(v7, 0); if (!v7_is_string(v)) { return V7_OK; } TString str = (const char*)v7_to_cstring(v7, &v); TString font; if (argc >= 2) { v7_val_t fontt = v7_arg(v7, 1); if (!v7_is_null(fontt) && !v7_is_undefined(fontt)) font = (const char*)v7_to_cstring(v7, &fontt); } int size = 0; if (argc >= 3) { v7_val_t sizee = v7_arg(v7, 2); if (v7_is_number(sizee)) size = floor(v7_to_number(sizee)); if (size < 10) size = 10; } TString col; if (argc >= 4) { v7_val_t coll = v7_arg(v7, 3); if (v7_is_string(coll)) col = (const char*)v7_to_cstring(v7, &coll); if (col.GetAt(0) != L'#' || col.GetLength() != 7) col = L""; } _activeBot->say(str, font, size, col); return V7_OK; }
int TFile::ReadString(TString &str) { int rp; if (feof(m_fHandle)) return 0; str = ""; while(rp = fgetc(m_fHandle), !feof(m_fHandle)) { if (rp == 0x0a || rp == 0x0d) { if (m_cend == -1) m_cend = rp; if (m_cend == rp) break; } else { str += char(rp); } } if (feof(m_fHandle)) return 0; return str.GetLength(); }
void VAISNAVADAY::GetFastingSubject(TString &strFest, int &nFast, TString &strFastSubj) { int nf, nf2; // default values nFast = 0; strFastSubj.Empty(); // finding fast subject nf = strFest.Find("[f:"); if (nf >= 0 && nf < strFest.GetLength()) { // ziskava typ postu nFast = strFest.GetAt(nf+3) - '0'; nf2 = strFest.Find("]", nf); if (nf2 >= 0) { strFest.Mid(nf + 5, nf2 - nf - 5, strFastSubj); } strFest.Delete(nf, strFest.GetLength() - nf); } }
//-------------------------------------------------------- // //-------------------------------------------------------- Bool TLString::ReadNextInteger(const TString& String,u32& CharIndex,s32& Integer) { // step over whitespace s32 NonWhitespaceIndex = String.GetCharIndexNonWhitespace( CharIndex ); // no more non-whitespace? no more data then if ( NonWhitespaceIndex == -1 ) return FALSE; // move char past whitespace CharIndex = (u32)NonWhitespaceIndex; s32 NextComma = String.GetCharIndex(',', CharIndex); s32 NextWhitespace = String.GetCharIndexWhitespace( CharIndex ); s32 NextSplit = String.GetLength(); if ( NextComma != -1 && NextComma < NextSplit ) NextSplit = NextComma; if ( NextWhitespace != -1 && NextWhitespace < NextSplit ) NextSplit = NextWhitespace; // split TTempString StringValue; StringValue.Append( String, CharIndex, NextSplit-CharIndex ); if ( !StringValue.GetInteger( Integer ) ) { TLDebug_Break("Failed to parse integer from string"); return FALSE; } // move string along past split CharIndex = NextSplit+1; // out of string if ( CharIndex >= String.GetLength() ) CharIndex = String.GetLength(); return TRUE; }
DWORD GetCol(const wchar_t* str) { int i = 0; TString strChk = str; if (strChk.GetLength() < 6) return 0; if (strChk.GetAt(i) == L'#') i++; wchar_t r[2], g[2], b[2]; r[0] = strChk.GetAt(i++); r[1] = strChk.GetAt(i++); g[0] = strChk.GetAt(i++); g[1] = strChk.GetAt(i++); b[0] = strChk.GetAt(i++); b[1] = strChk.GetAt(i); int rr = h2a2(r); int gg = h2a2(g); int bb = h2a2(b); return RGB(rr, gg, bb); }
void Bot::setFontStyle(TString& fontName, int fontSize, COLORREF fontColor) { if (!fontName.IsEQ(L"")) memcpy(_charset.font, fontName.GetAsChar(), fontName.GetLength() * sizeof(char)); if (fontSize != NULL) _charset.size = fontSize; if (fontColor != NULL) _charset.color = fontColor; }
//-------------------------------------------------------- // //-------------------------------------------------------- SyncBool TLFile::ImportBinaryData(const TString& DataString,TBinary& BinaryData,TRef DataType) { /* // work out the type of data TRefRef BinaryDataType = BinaryData.GetDataTypeHint(); // check for conflicting type hints if ( DataType.IsValid() && BinaryDataType.IsValid() && DataType != BinaryDataType ) { TDebugString Debug_String; Debug_String << "Data import type hint mismatch; Tried to import as " << DataType << " but binary says it's " << BinaryDataType; TLDebug_Break( Debug_String ); // fall through to use the data type embedded in the binary data DataType = BinaryDataType; } else if ( BinaryDataType.IsValid() && !DataType.IsValid() ) { // use the type specified in the binary DataType = BinaryDataType; } */ // import the data based on the type u32 CharIndex = 0; switch ( DataType.GetData() ) { case TLBinary_TypeRef(float): { float f; if ( !TLString::ReadNextFloatArray( DataString, CharIndex, &f, 1 ) ) return SyncFalse; BinaryData.Write( f ); return SyncTrue; } case TLBinary_TypeRef(float2): { float2 f; if ( !TLString::ReadNextFloatArray( DataString, CharIndex, f.GetData(), f.GetSize() ) ) return SyncFalse; BinaryData.Write( f ); return SyncTrue; } case TLBinary_TypeRef(float3): { float3 f; if ( !TLString::ReadNextFloatArray( DataString, CharIndex, f.GetData(), f.GetSize() ) ) return SyncFalse; BinaryData.Write( f ); return SyncTrue; } case TLBinary_TypeRef(float4): { float4 f; if ( !TLString::ReadNextFloatArray( DataString, CharIndex, f.GetData(), f.GetSize() ) ) return SyncFalse; BinaryData.Write( f ); return SyncTrue; } case TLBinary_TypeRef(TQuaternion): { float4 f; if ( !TLString::ReadNextFloatArray( DataString, CharIndex, f.GetData(), f.GetSize() ) ) return SyncFalse; // convert to normalised quaternion TLMaths::TQuaternion Quat( f ); Quat.Normalise(); BinaryData.Write( Quat ); return SyncTrue; } case TLBinary_TypeRef(TEuler): { float3 f; if ( !TLString::ReadNextFloatArray( DataString, CharIndex, f.GetData(), f.GetSize() ) ) return SyncFalse; // convert to Euler type TLMaths::TEuler Euler( f ); BinaryData.Write( Euler ); return SyncTrue; } case TLBinary_TypeRef(TAxisAngle): { float4 f; if ( !TLString::ReadNextFloatArray( DataString, CharIndex, f.GetData(), f.GetSize() ) ) return SyncFalse; // convert to normalised quaternion TLMaths::TAxisAngle AxisAngle( f ); BinaryData.Write( AxisAngle ); return SyncTrue; } case TLBinary_TypeRef(TRef): { TRef Ref( DataString ); BinaryData.Write( Ref ); return SyncTrue; } case TLBinary_TypeRef_String: { // do string cleanup, convert "\n" to a linefeed etc if ( TLString::IsStringDirty( DataString ) ) { TString OutputString = DataString; TLString::CleanString( OutputString ); BinaryData.WriteString( OutputString ); } else { // already clean, just write the original BinaryData.WriteString( DataString ); } return SyncTrue; } case TLBinary_TypeRef(TColour): { float4 f; if ( !TLString::ReadNextFloatArray( DataString, CharIndex, f.GetData(), f.GetSize() ) ) return SyncFalse; // check range // gr: use TLDebug_CheckInRange() ? if ( f.x > 1.0f || f.x < 0.0f || f.y > 1.0f || f.y < 0.0f || f.z > 1.0f || f.z < 0.0f || f.w > 1.0f || f.w < 0.0f ) { if ( !TLDebug_Break( TString("Colour float type has components out of range (0..1); %.3f,%.3f,%.3f,%.3f", f.x, f.y, f.z, f.w) ) ) return SyncFalse; } TColour Colour( f ); BinaryData.Write( Colour ); return SyncTrue; } case TLBinary_TypeRef(TColour24): { Type3<s32> Colours; if ( !TLString::ReadNextInteger( DataString, CharIndex, Colours.x ) ) return SyncFalse; if ( !TLString::ReadNextInteger( DataString, CharIndex, Colours.y ) ) return SyncFalse; if ( !TLString::ReadNextInteger( DataString, CharIndex, Colours.z ) ) return SyncFalse; // check range // gr: use TLDebug_CheckInRange() ? if ( Colours.x > 255 || Colours.x < 0 || Colours.y > 255 || Colours.y < 0 || Colours.z > 255 || Colours.z < 0 ) { if ( !TLDebug_Break( TString("Colour24 type has components out of range (0..255); %d,%d,%d", Colours.x, Colours.y, Colours.z ) ) ) return SyncFalse; } TColour24 Colour( Colours.x, Colours.y, Colours.z ); BinaryData.Write( Colour ); return SyncTrue; } case TLBinary_TypeRef(TColour32): { Type4<s32> Colours; if ( !TLString::ReadNextInteger( DataString, CharIndex, Colours.x ) ) return SyncFalse; if ( !TLString::ReadNextInteger( DataString, CharIndex, Colours.y ) ) return SyncFalse; if ( !TLString::ReadNextInteger( DataString, CharIndex, Colours.z ) ) return SyncFalse; if ( !TLString::ReadNextInteger( DataString, CharIndex, Colours.w ) ) return SyncFalse; // check range // gr: use TLDebug_CheckInRange() ? if ( Colours.x > 255 || Colours.x < 0 || Colours.y > 255 || Colours.y < 0 || Colours.z > 255 || Colours.z < 0 || Colours.w > 255 || Colours.w < 0 ) { if ( !TLDebug_Break( TString("Colour32 type has components out of range (0..255); %d,%d,%d,%d", Colours.x, Colours.y, Colours.z, Colours.w ) ) ) return SyncFalse; } TColour32 Colour( Colours.x, Colours.y, Colours.z, Colours.w ); BinaryData.Write( Colour ); return SyncTrue; } case TLBinary_TypeRef(TColour64): { Type4<s32> Colours; if ( !TLString::ReadNextInteger( DataString, CharIndex, Colours.x ) ) return SyncFalse; if ( !TLString::ReadNextInteger( DataString, CharIndex, Colours.y ) ) return SyncFalse; if ( !TLString::ReadNextInteger( DataString, CharIndex, Colours.z ) ) return SyncFalse; if ( !TLString::ReadNextInteger( DataString, CharIndex, Colours.w ) ) return SyncFalse; // check range // gr: use TLDebug_CheckInRange() ? if ( Colours.x > 65535 || Colours.x < 0 || Colours.y > 65535 || Colours.y < 0 || Colours.z > 65535 || Colours.z < 0 || Colours.w > 65535 || Colours.w < 0 ) { if ( !TLDebug_Break( TString("Colour64 type has components out of range (0..65535); %d,%d,%d,%d", Colours.x, Colours.y, Colours.z, Colours.w ) ) ) return SyncFalse; } TColour64 Colour( Colours.x, Colours.y, Colours.z, Colours.w ); BinaryData.Write( Colour ); return SyncTrue; } case TLBinary_TypeRef(u8): return ImportBinaryDataIntegerInRange<u8>( BinaryData, DataString ); case TLBinary_TypeRef(s8): return ImportBinaryDataIntegerInRange<s8>( BinaryData, DataString ); case TLBinary_TypeRef(u16): return ImportBinaryDataIntegerInRange<u16>( BinaryData, DataString ); case TLBinary_TypeRef(s16): return ImportBinaryDataIntegerInRange<s16>( BinaryData, DataString ); case TLBinary_TypeRef(u32): return ImportBinaryDataIntegerInRange<u32>( BinaryData, DataString ); case TLBinary_TypeRef(s32): return ImportBinaryDataIntegerInRange<s32>( BinaryData, DataString ); case TLBinary_TypeRef(Bool): { // read first char, we can work out true/false/0/1 from that if ( DataString.GetLength() == 0 ) return SyncFalse; const TChar& BoolChar = DataString.GetCharAt(0); if ( BoolChar == 't' || BoolChar == 'T' || BoolChar == '1' ) { BinaryData.Write( (Bool)TRUE ); return SyncTrue; } else if ( BoolChar == 'f' || BoolChar == 'F' || BoolChar == '0' ) { BinaryData.Write( (Bool)FALSE ); return SyncTrue; } else { TLDebug_Break("Bool data is not True,False,0 or 1"); return SyncFalse; } } default: break; }; TDebugString Debug_String; Debug_String << "Unsupported/todo data type " << DataType << ". Data string: [" << DataString << "]"; TLDebug_Break( Debug_String ); return SyncFalse; }