dword String::LEqual(const String& s) const { #ifdef CPU_64 int l = GetCount(); if(s.GetCount() != l) return 1; const qword *qa = (const qword *)Begin(); const qword *qb = (const qword *)s.Begin(); while(l >= 8) { if(*qa++ != *qb++) return 1; l -= 8; } const dword *da = (const dword *)qa; const dword *db = (const dword *)qb; if((l & 4) && *da++ != *db++) return 1; #else int l = GetCount(); if(s.GetCount() != l) return 1; const dword *da = (const dword *)Begin(); const dword *db = (const dword *)s.Begin(); while(l >= 4) { if(*da++ != *db++) return 1; l -= 4; } #endif const word *wa = (const word *)da; const word *wb = (const word *)db; if((l & 2) && *wa++ != *wb++) return 1; return (l & 1) ? *(const char *)wa != *(const char *)wb : 0; }
Url::Url(const String& base_url) { String url = base_url; if (url.GetLength() == 0) BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid URL Empty URL.")); size_t pHelper = url.Find(":"); if (pHelper != String::NPos) { if (!ParseScheme(url.SubStr(0, pHelper))) BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid URL Scheme.")); url = url.SubStr(pHelper + 1); } if (*url.Begin() != '/') BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid URL: '/' expected after scheme.")); if (url.GetLength() == 1) { return; } if (*(url.Begin() + 1) == '/') { pHelper = url.Find("/", 2); if (pHelper == String::NPos) BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid URL: Missing '/' after authority.")); if (!ParseAuthority(url.SubStr(0, pHelper))) BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid URL Authority")); url = url.SubStr(pHelper); } if (*url.Begin() == '/') { pHelper = url.FindFirstOf("#?"); if (!ParsePath(url.SubStr(1, pHelper - 1))) BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid URL Path")); if (pHelper != String::NPos) url = url.SubStr(pHelper); } else BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid URL: Missing path.")); if (*url.Begin() == '?') { pHelper = url.Find("#"); if (!ParseQuery(url.SubStr(1, pHelper - 1))) BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid URL Query")); if (pHelper != String::NPos) url = url.SubStr(pHelper); } if (*url.Begin() == '#') { if (!ParseFragment(url.SubStr(1))) BOOST_THROW_EXCEPTION(std::invalid_argument("Invalid URL Fragment")); } }
// Read and save messages and their attachments void ReadMessageTest(MAPIEx& mapi, const String &folderName = "") { puts("\nRead and save message test"); MAPIFolder folder; if (folderName.IsEmpty()) { if(!mapi.OpenInbox(folder)) return; } else { if(!mapi.OpenFolder(folderName, folder)) // Instead of Inbox open selected folder return; } // use SortContents to sort the messages, default is ascending by PR_MESSAGE_DELIVERY_TIME folder.SortContents(TABLE_SORT_DESCEND); //mapi.SetUnreadOnly(); MAPIMessage message; while(folder.GetNextMessage(message)) { Time receivedTime = message.GetReceivedTime(); Time submitTime = message.GetSubmitTime(); Time modifTime = message.GetLastModificationTime(); String recipients; if (message.GetRecipients()) { String name, email; int type; while (message.GetNextRecipient(name, email, type)) { if (!recipients.IsEmpty()) recipients += "; "; String stype; if (type == MAPI_TO) stype = "TO"; else if (type == MAPI_CC) stype = "CC"; else if (type == MAPI_BCC) stype = "BCC"; else stype = "Unknown!"; recipients += Format("'%s' (%s)(%s)", name, email, stype.Begin()); } } puts(Format("Message from '%s' (%s) to %s subject '%s', received time: %s, " "sent time: %s, modif time: %s", message.GetSenderName(), message.GetSenderEmail(), recipients, message.GetSubject(), Format(receivedTime), Format(submitTime), Format(modifTime))); puts(Format("Body: %s", message.GetBody(false))); //puts(Format("HTML: %s", message.GetHTML())); if(message.GetAttachmentCount()) { printf(Format("Saving attachments to %s...", MSG_ATTACHMENT_FOLDER)); message.SaveAttachment(MSG_ATTACHMENT_FOLDER); puts("done"); } static int num; String fileName = "c:\\temp\\" + FormatInt(num) + ".msg"; printf(Format("Saving message to %s ...", fileName.Begin())); message.SaveToFile(fileName); num++; puts("done"); } }
static String VFKParseDOPLKOD(String s) { const char *p = s; while(*p && !(p[0] == '/' && p[1] == ' ' && p[2] == 'D' && p[3] == 'O' && p[4] == 'P' && p[5] == 'L' && p[6] == 'K' && p[7] == 'O' && p[8] == 'D')) p++; if(!*p) return s; while(p > s.Begin() && (byte)p[-1] <= ' ') p--; return s.Left(p - s.Begin()); }
bool String::operator==(const String& str) const { if (Length() != str.Length()) { return false; } if (Begin() == str.Begin()) { return true; } return Algo::Range::Equal(Begin(), End(), str.Begin()); }
bool ODBCPerformScript(const String& text, StatementExecutor& executor, Gate2<int, int> progress_canceled) { const char *p = text; while(*p) { String cmd; while(*p && *p != ';') if(*p == '\'') { const char *s = p; while(*++p && (*p != '\'' || *++p == '\'')) ; cmd.Cat(s, int(p - s)); } else { if(*p > ' ') cmd.Cat(*p); else if(!cmd.IsEmpty() && *cmd.Last() != ' ') cmd.Cat(' '); p++; } if(progress_canceled(int(p - text.Begin()), text.GetLength())) return false; if(!IsNull(cmd) && !executor.Execute(cmd)) return false; if(*p == ';') p++; } return true; }
//----------------------------------------------------------------------------------------------------------------------------------------------------- VOID Configuration::LoadConfigFile(LPCTSTR Filename) { TextStream T(File::Open(Filename, FileMode::OPEN)); while(!T.EndOfStream()) { String L = T.ReadLine(); if (L.BeginsWith("#")) continue; String::Iterator i = L.Find('='); if (i != L.End()) { String Name = L.Substr(L.Begin(), i); String Value = L.Substr(i+1, L.End()); if (m_Schema.Contains(Name)) { Item I = m_Schema.Get(Name); if ((I.m_Source & ConfigurationSource::FILE) == 0) continue; I.m_Present = TRUE; } m_ConfigValues.Add(Name,Value); } } }
bool Sqlite3PerformScript(const String& txt, StatementExecutor& se, Gate2<int, int> progress_canceled) { const char *text = txt; for(;;) { String stmt; while(*text <= 32 && *text > 0) text++; if(*text == '\0') break; for(;;) { if(*text == '\0') break; if(*text == ';') break; else if(*text == '\'') text = Sqlite3ReadString(text, stmt); else if(*text == '\"') text = Sqlite3ReadString(text, stmt); else stmt.Cat(*text++); } if(progress_canceled(text - txt.Begin(), txt.GetLength())) return false; if(!se.Execute(stmt)) return false; if(*text) text++; } return true; }
bool JSONFile::Save(Stream& dest) { PROFILE(SaveJSONFile); String buffer; root.ToString(buffer); return dest.Write(buffer.Begin().ptr, buffer.Length()) == buffer.Length(); }
bool SslKey::Load(const String& data) { Clear(); SslStream strm; if(!strm.OpenBuffer(data.Begin(), data.GetLength())) return false; return Set(PEM_read_bio_PrivateKey(strm, NULL, NULL, NULL)); }
void JSONValue::WriteJSONString(String& dest, const String& str) { dest += '\"'; for (String::ConstIterator it = str.Begin(); it != str.End(); ++it) { char c = *it; if (c >= 0x20 && c != '\"' && c != '\\') dest += c; else { dest += '\\'; switch (c) { case '\"': case '\\': dest += c; break; case '\b': dest += 'b'; break; case '\f': dest += 'f'; break; case '\n': dest += 'n'; break; case '\r': dest += 'r'; break; case '\t': dest += 't'; break; default: { char buffer[6]; sprintf(buffer, "u%04x", c); dest += (const char*)&buffer[0]; } break; } } } dest += '\"'; }
String NormalizePath(const char *path, const char *currdir) { String join_path; if(!IsFullPath(path)) path = join_path = AppendFileName(currdir, path); String out; if(*path && path[1] == ':') { out << path[0] << ":\\"; path += 3; } else if(path[0] == '\\' && path[1] == '\\') { out = "\\\\"; path += 2; } else if(sDirSep(*path)) { if(*currdir) out << *currdir << ':'; out.Cat(DIR_SEP); path++; } int outstart = out.GetLength(); while(*path) { if(sDirSep(*path)) { while(sDirSep(*path)) path++; if(*path == '\0') break; if(out.IsEmpty() || *out.Last() != DIR_SEP) out.Cat(DIR_SEP); } const char *b = path; while(*path && !sDirSep(*path)) path++; if(path - b == 1 && *b == '.') ; //no-op else if(path - b == 2 && *b == '.' && b[1] == '.') { const char *ob = ~out + outstart, *oe = out.End(); if(oe - 1 > ob && oe[-1] == DIR_SEP) oe--; while(oe > ob && oe[-1] != DIR_SEP) oe--; out.Trim((int)(oe - out.Begin())); } else out.Cat(b, (int)(path - b)); } return out; }
String String::Concat(const String& str) const { String result; if (HasChars() || str.HasChars()) { result.Allocate(Length() + str.Length()); Iterator dest = Algo::Range::Copy(Begin(), End(), result.MutableBegin()); Algo::Range::Copy(str.Begin(), str.End(), dest); } return result; }
String SpinBox::MinimumValueText() const { size_type len = 0; (*API->SpinBox->GetSpinBoxMinimumValueText)( handle, 0, &len ); String text; if ( len > 0 ) { text.SetLength( len ); if ( (*API->SpinBox->GetSpinBoxMinimumValueText)( handle, text.Begin(), &len ) == api_false ) throw APIFunctionError( "GetSpinBoxMinimumValueText" ); text.ResizeToNullTerminated(); } return text; }
String Label::Text() const { size_type len = 0; (*API->Label->GetLabelText)( handle, 0, &len ); String text; if ( len > 0 ) { text.SetLength( len ); if ( (*API->Label->GetLabelText)( handle, text.Begin(), &len ) == api_false ) throw APIFunctionError( "GetLabelText" ); text.ResizeToNullTerminated(); } return text; }
String TabBox::PageToolTip( int idx ) const { size_type len = 0; (*API->TabBox->GetTabBoxPageToolTip)( handle, idx, 0, &len ); String tip; if ( len > 0 ) { tip.SetLength( len ); if ( (*API->TabBox->GetTabBoxPageToolTip)( handle, idx, tip.Begin(), &len ) == api_false ) throw APIFunctionError( "GetTabBoxPageToolTip" ); tip.ResizeToNullTerminated(); } return tip; }
String FileFormat::Implementation() const { size_type len = 0; (*API->FileFormat->GetFileFormatImplementation)( m_data->handle, 0, &len ); String implementation; if ( len > 0 ) { implementation.SetLength( len ); if ( (*API->FileFormat->GetFileFormatImplementation)( m_data->handle, implementation.Begin(), &len ) == api_false ) throw APIFunctionError( "GetFileFormatImplementation" ); implementation.ResizeToNullTerminated(); } return implementation; }
String FileFormatInstance::FilePath() const { size_type len = 0; (*API->FileFormat->GetImageFilePath)( handle, 0, &len ); String path; if ( len > 0 ) { path.SetLength( len ); if ( (*API->FileFormat->GetImageFilePath)( handle, path.Begin(), &len ) == api_false ) throw APIFunctionError( "GetImageFilePath" ); path.ResizeToNullTerminated(); } return path; }
String TreeBox::Node::ToolTip( int col ) const { size_type len = 0; (*API->TreeBox->GetTreeBoxNodeColToolTip)( handle, col, 0, &len ); String tip; if ( len > 0 ) { tip.SetLength( len ); if ( (*API->TreeBox->GetTreeBoxNodeColToolTip)( handle, col, tip.Begin(), &len ) == api_false ) throw APIFunctionError( "GetTreeBoxNodeColToolTip" ); tip.ResizeToNullTerminated(); } return tip; }
String FileFormatInstance::ImageProperties() const { size_type len = 0; (*API->FileFormat->GetImageProperties)( handle, 0, &len ); String properties; if ( len > 0 ) { properties.SetLength( len ); if ( (*API->FileFormat->GetImageProperties)( handle, properties.Begin(), &len ) == api_false ) throw APIFunctionError( "GetImageProperties" ); properties.ResizeToNullTerminated(); } return properties; }
String ProcessParameter::ScriptComment() const { size_type len = 0; (*API->Process->GetParameterScriptComment)( m_data->handle, 0, &len ); String comment; if ( len > 0 ) { comment.SetLength( len ); if ( (*API->Process->GetParameterScriptComment)( m_data->handle, comment.Begin(), &len ) == api_false ) throw APIFunctionError( "GetParameterScriptComment" ); comment.ResizeToNullTerminated(); } return comment; }
String ProcessParameter::Description() const { size_type len = 0; (*API->Process->GetParameterDescription)( m_data->handle, 0, &len ); String description; if ( len > 0 ) { description.SetLength( len ); if ( (*API->Process->GetParameterDescription)( m_data->handle, description.Begin(), &len ) == api_false ) throw APIFunctionError( "GetParameterDescription" ); description.ResizeToNullTerminated(); } return description; }
String FileFormat::Status() const { size_type len = 0; (*API->FileFormat->GetFileFormatStatus)( m_data->handle, 0, &len, 0/*reserved*/ ); String status; if ( len > 0 ) { status.SetLength( len ); if ( (*API->FileFormat->GetFileFormatStatus)( m_data->handle, status.Begin(), &len, 0/*reserved*/ ) == api_false ) throw APIFunctionError( "GetFileFormatStatus" ); status.ResizeToNullTerminated(); } return status; }
String TreeBox::Node::Text( int col ) const { size_type len = 0; (*API->TreeBox->GetTreeBoxNodeColText)( handle, col, 0, &len ); String text; if ( len > 0 ) { text.SetLength( len ); if ( (*API->TreeBox->GetTreeBoxNodeColText)( handle, col, text.Begin(), &len ) == api_false ) throw APIFunctionError( "GetTreeBoxNodeColText" ); text.ResizeToNullTerminated(); } return text; }
String TabBox::PageLabel( int idx ) const { size_type len = 0; (*API->TabBox->GetTabBoxPageLabel)( handle, idx, 0, &len ); String label; if ( len > 0 ) { label.SetLength( len ); if ( (*API->TabBox->GetTabBoxPageLabel)( handle, idx, label.Begin(), &len ) == api_false ) throw APIFunctionError( "GetTabBoxPageLabel" ); label.ResizeToNullTerminated(); } return label; }
String SpinBox::Suffix() const { size_type len = 0; (*API->SpinBox->GetSpinBoxSuffix)( handle, 0, &len ); String suffix; if ( len > 0 ) { suffix.SetLength( len ); if ( (*API->SpinBox->GetSpinBoxSuffix)( handle, suffix.Begin(), &len ) == api_false ) throw APIFunctionError( "GetSpinBoxSuffix" ); suffix.ResizeToNullTerminated(); } return suffix; }
bool String::operator>(const String& str) const { ConstIterator iterLeft = Begin(), iterRight = str.Begin(); while (iterLeft != End() && iterRight != str.End()) { if (*iterLeft != *iterRight) { return *iterLeft > *iterRight; } ++iterLeft; ++iterRight; } return (Length() > str.Length()); }
void StringBuffer::Set(String& s) { s.UnShare(); int l = s.GetLength(); if(s.GetAlloc() == 14) { begin = (char *)MAlloc_S(); limit = begin + 31; memcpy(begin, s.Begin(), l); end = begin + l; } else { begin = s.ptr; end = begin + l; limit = begin + s.GetAlloc(); } s.Zero(); }
Collection::Pair<bool,String::ConstIterator> String::FindLast(const String& str) const { if (str.Length() <= Length()) { ConstIterator pos = End() - str.Length(), last = Begin(); do { if (Algo::Range::Equal(pos, pos + str.Length(), str.Begin())) { return Collection::Pair<bool,ConstIterator>(true, pos); } } while(pos-- != last); } return Collection::Pair<bool,ConstIterator>(false, nullptr); }
void String::CreateReference(const String& str, ConstIterator begin, ConstIterator end) { if (begin < str.Begin() || end > str.End() || begin >= end) { throw IllegalArgumentException(SAF_SOURCE_LOCATION, String("Invalid substring bounds.")); } if (str.m_buffer->m_refCounter == Type::NumericLimits<Size>::Max()) { throw OverflowException(SAF_SOURCE_LOCATION, String("Reference counter overflow.")); } m_buffer = str.m_buffer; m_begin = m_buffer->m_data + (begin - m_buffer->m_data); // Hack to get rid of const m_length = end - begin; ++m_buffer->m_refCounter; }