本文整理汇总了C++中STRING::length方法的典型用法代码示例。如果您正苦于以下问题:C++ STRING::length方法的具体用法?C++ STRING::length怎么用?C++ STRING::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类STRING
的用法示例。
在下文中一共展示了STRING::length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Trim
bool JustRenderIt::ResourceManager::GetResourcePath(STRING& filename,
STRING folderName)
{
Trim(filename);
Trim(folderName);
if(folderName[folderName.length()-1] == '/' ||
folderName[folderName.length()-1] == '\\' )
folderName = folderName.substr(0, folderName.length()-1);
if(folderName[0] == '/')
folderName = folderName.substr(1, folderName.length()-1);
if(!FileExists(filename))
{
STRING newfilename = "../resources/";
newfilename += folderName + "/" + filename;
if(!FileExists(newfilename))
{
char str[256];
sprintf(str, "Couldn't open \"%s\"", filename.c_str());
LOG_ERROR1(str);
return false;
}
filename = newfilename;
}
return true;
}
示例2: while
// Immediate concatenation ( += ) operator{}
// This operator will be overloaded to
// work with a right hand value of either type STRING, type char* or type char.
STRING STRING::operator += (const STRING &right_argument)
{
unsigned newLength = this->len + right_argument.length();
int new_length = this->len;
char* temp = new char[new_length];
// Copy the left hand argument into a temporary char array
// so we can delete its contents and reallocate more memory
for(unsigned i = 0; i < this->len; i++)
temp[i] = this->contents[i];
delete[] this->contents;
this->contents = new char[newLength];
unsigned i = 0;
// Copy the first string's contents back in.
// Must be a while loop for proper scoping of i.
while (i < this->len)
{
this->contents[i] = temp[i];
i++;
}
// Copy the second string's contents in.
for (unsigned j = 0; j < right_argument.length(); j++)
this->contents[i + j] = right_argument.contents[j];
this->len = newLength;
return *this;
}
示例3: GetParenthesisedList
// Break up a string composed of multiple sections in parentheses into a collection
// of sub-strings. Sample input string: (Hello)(World1,World2)
MgStringCollection* WfsGetFeatureParams::GetParenthesisedList(CREFSTRING sourceString)
{
MgStringCollection* stringList = new MgStringCollection();
if(sourceString.length() > 0)
{
// Create a collection of strings
STRING remaining = MgUtil::Trim(sourceString);
while(remaining.length() > 0)
{
STRING::size_type openParenthesis = remaining.find_first_of(L"(");
if(openParenthesis != string::npos)
{
STRING::size_type closeParenthesis = remaining.find_first_of(L")");
if(closeParenthesis != string::npos)
{
STRING thisString = remaining.substr(openParenthesis + 1, closeParenthesis - openParenthesis - 1);
stringList->Add(thisString);
remaining = remaining.substr(closeParenthesis + 1);
}
}
else
{
stringList->Add(remaining);
break;
}
}
}
return stringList;
}
示例4:
CKT::CVersion::CVersion(STRING version)
{
int iPoint = version.find('.');
STRING sTemp = version.substr(0, iPoint);
m_byMajor = (BYTE)toInt(sTemp.c_str());
sTemp = version.substr(iPoint + 1, version.length() - iPoint);
m_byMinor = (BYTE)toInt(sTemp.c_str());
}
示例5: ToXml
/////////////////////////////////////////
// Write feature information as XML document.
//
MgByteReader* MgFeatureInformation::ToXml()
{
STRING xml;
STRING xmlSelection = m_selection? m_selection->ToXml(false): L"";
// TODO: define a schema for this XML
xml.append(L"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<FeatureInformation>\n");
size_t len = xmlSelection.length();
if(len > 0)
{
xml.reserve(len + 2048);
xml.append(xmlSelection);
}
else
{
xml.reserve(2048);
xml.append(L"<FeatureSet />\n");
}
if(m_tooltip.length() > 0)
{
xml.append(L"<Tooltip>");
xml.append(MgUtil::ReplaceEscapeCharInXml(m_tooltip));
xml.append(L"</Tooltip>\n");
}
else
xml.append(L"<Tooltip />\n");
if(m_hyperlink.length() > 0)
{
xml.append(L"<Hyperlink>");
xml.append(MgUtil::ReplaceEscapeCharInXml(m_hyperlink));
xml.append(L"</Hyperlink>\n");
}
else
xml.append(L"<Hyperlink />\n");
if(m_properties != NULL)
{
for(int i = 0; i < m_properties->GetCount(); i++)
{
Ptr<MgStringProperty> prop = (MgStringProperty*)m_properties->GetItem(i);
xml.append(L"<Property name=\"");
xml.append(MgUtil::ReplaceEscapeCharInXml(prop->GetName()));
xml.append(L"\" value=\"");
xml.append(MgUtil::ReplaceEscapeCharInXml(prop->GetValue()));
xml.append(L"\" />\n");
}
}
xml.append(L"</FeatureInformation>\n");
string xmlDoc = MgUtil::WideCharToMultiByte(xml);
STRING mimeType = L"text/xml";
return MgUtil::GetByteReader(xmlDoc, &mimeType);
}
示例6: testEmptyConst
void testEmptyConst()
{
char desc[] = "Empty Constructor";
printTestHeader(desc);
STRING s;
cout << "STRING contains '"; STRdisplay(s); cout << "'.\n"
<< "STRING length is " << s.length() << ".\n"
<< "isEmpty returns " << (s.isEmpty() ? "True" : "False") << ".\n";
printTestFooter(desc);
}
示例7: removePath
/*
* Remove the path from a file name, perserving folders.
* preserveFrom should carry a trailing \.
*/
STRING removePath(const STRING str, const STRING preserveFrom)
{
const int pos = str.find(preserveFrom);
if (pos != str.npos)
{
return str.substr(pos + preserveFrom.length());
}
// Return the path unaltered, since it didn't contain the
// default folder and any other folders should be subfolders
// (although a different default folder may be present).
return str;
}
示例8: Deserialize
/////////////////////////////////////////
// Deserialize from a stream
//
void MgFeatureInformation::Deserialize(MgStream* stream)
{
STRING xml;
stream->GetString(xml);
if(xml.length() > 0)
{
m_selection = new MgSelection();
m_selection->FromXml(xml);
}
stream->GetString(m_tooltip);
stream->GetString(m_hyperlink);
m_properties = (MgPropertyCollection*)stream->GetObject();
}
示例9: testSingleCharConst
void testSingleCharConst()
{
char desc[] = "Single Character Constructor";
printTestHeader(desc);
char c = 'd';
cout << "Assigned char is '" << c << "'. \n";
STRING s (c);
cout << "STRING contains '"; STRdisplay(s); cout << "'.\n"
<< "STRING length is " << s.length() << ".\n";
printTestFooter(desc);
}
示例10: BuildFilterStrings
// Build OGC filter XML stirngs based on the provided input filters.
void WfsGetFeatureParams::BuildFilterStrings(CREFSTRING filters, CREFSTRING featureIds, CREFSTRING bbox)
{
// Create the required feature filters
m_filterStrings = GetParenthesisedList(filters);
if(m_filterStrings->GetCount() == 0)
{
// If no FILTER was specified, look for a BBOX
if(bbox.length() > 0)
{
// Build a filter from the bounding box
Ptr<MgStringCollection> bboxCoords = MgStringCollection::ParseCollection(bbox, L",");
if(bboxCoords->GetCount() >= 4)
{
// TODO: Look into using StringStream and XmlElementEmitter for simplified generation
// of these elements.
STRING filterString = L"<ogc:Filter><ogc:BBOX><ogc:PropertyName>%MG_GEOM_PROP%</ogc:PropertyName><gml:Box><gml:coordinates>";
filterString.append(MgUtil::Trim(bboxCoords->GetItem(0)));
filterString.append(L",");
filterString.append(MgUtil::Trim(bboxCoords->GetItem(1)));
filterString.append(L" ");
filterString.append(MgUtil::Trim(bboxCoords->GetItem(2)));
filterString.append(L",");
filterString.append(MgUtil::Trim(bboxCoords->GetItem(3)));
filterString.append(L"</gml:coordinates></gml:Box></ogc:BBOX></ogc:Filter>");
m_filterStrings->Add(filterString);
}
}
// If no FILTER or BBOX, look for FEATUREID
else if(featureIds.length() > 0)
{
// Build a filter from the list of feature Ids
Ptr<MgStringCollection> featureIdList = MgStringCollection::ParseCollection(featureIds, L",");
if(featureIdList->GetCount() > 0)
{
STRING filterString = L"<ogc:Filter>";
for(int i = 0; i < featureIdList->GetCount(); i++)
{
STRING thisFeatureId = MgUtil::Trim(featureIdList->GetItem(i));
if(thisFeatureId.length() > 0)
{
filterString.append(L"<ogc:GmlObjectId gml:id=");
filterString.append(thisFeatureId);
filterString.append(L"/>");
}
}
filterString.append(L"</ogc:Filter>");
m_filterStrings->Add(filterString);
}
}
}
}
示例11: testNullcstr
void testNullcstr()
{
char desc[] = "Null Char* Constructor";
printTestHeader(desc);
char* cstr = NULL;
if (cstr == NULL) cout << "The contents of the C-String are: \n\t'" << "NULL" << "'.\n";
STRING s (cstr);
cout << s.length() << endl;
cout << "The contents of STRING are: \n\t'"; STRdisplay(s); cout << "'.\n";
cout << "Success.\n";
printTestFooter(desc);
}
示例12: res_it
// Returns the null terminated UTF-8 encoded text string for the current
// object at the given level. Use delete [] to free after use.
char* LTRResultIterator::GetUTF8Text(PageIteratorLevel level) const {
if (it_->word() == NULL) return NULL; // Already at the end!
STRING text;
PAGE_RES_IT res_it(*it_);
WERD_CHOICE* best_choice = res_it.word()->best_choice;
ASSERT_HOST(best_choice != NULL);
if (level == RIL_SYMBOL) {
text = res_it.word()->BestUTF8(blob_index_, false);
} else if (level == RIL_WORD) {
text = best_choice->unichar_string();
} else {
bool eol = false; // end of line?
bool eop = false; // end of paragraph?
do { // for each paragraph in a block
do { // for each text line in a paragraph
do { // for each word in a text line
best_choice = res_it.word()->best_choice;
ASSERT_HOST(best_choice != NULL);
text += best_choice->unichar_string();
text += " ";
res_it.forward();
eol = res_it.row() != res_it.prev_row();
} while (!eol);
text.truncate_at(text.length() - 1);
text += line_separator_;
eop = res_it.block() != res_it.prev_block() ||
res_it.row()->row->para() != res_it.prev_row()->row->para();
} while (level != RIL_TEXTLINE && !eop);
if (eop) text += paragraph_separator_;
} while (level == RIL_BLOCK && res_it.block() == res_it.prev_block());
}
int length = text.length() + 1;
char* result = new char[length];
strncpy(result, text.string(), length);
return result;
}
示例13: IsInteger
const std::vector <STRING> OSInterface::ExtractFilesFromDirectory(const STRING& aRootDir,const STRING& aExtension)
{
STRING pathOfFile;
STRING patternOfString;
WIN32_FIND_DATA fileInfo;
patternOfString = aRootDir + _T("\\*.*") ;
HANDLE hToFile = ::FindFirstFile(patternOfString.c_str(), &fileInfo);
std::vector<STRING> aDirFiles;
if(hToFile != INVALID_HANDLE_VALUE)
{
do
{
if(fileInfo.cFileName[0] != '.')
{
pathOfFile.erase();
pathOfFile = aRootDir + _T("\\")+ fileInfo.cFileName;
STRING file = fileInfo.cFileName;
STRING extOfString = file.substr(file.rfind(_T(".")) + 1);
if(aExtension.length())
{
if(extOfString == aExtension)
{
aDirFiles.push_back(pathOfFile);
}
}
else
{
bool valid = IsInteger(file);
if(valid)
{
aDirFiles.push_back(pathOfFile);
}
}
}
}while(::FindNextFile(hToFile , &fileInfo));
::FindClose(hToFile);
}
return aDirFiles;
}
示例14: pp
/**
* Returns the null terminated UTF-8 encoded text string for the current
* object at the given level. Use delete [] to free after use.
*/
char* ResultIterator::GetUTF8Text(PageIteratorLevel level) const {
if (it_->word() == NULL) return NULL; // Already at the end!
STRING text;
switch (level) {
case RIL_BLOCK:
{
ResultIterator pp(*this);
do {
pp.AppendUTF8ParagraphText(&text);
} while (pp.Next(RIL_PARA) && pp.it_->block() == it_->block());
}
break;
case RIL_PARA:
AppendUTF8ParagraphText(&text);
break;
case RIL_TEXTLINE:
{
ResultIterator it(*this);
it.MoveToLogicalStartOfTextline();
it.IterateAndAppendUTF8TextlineText(&text);
}
break;
case RIL_WORD:
AppendUTF8WordText(&text);
break;
case RIL_SYMBOL:
{
bool reading_direction_is_ltr =
current_paragraph_is_ltr_ ^ in_minor_direction_;
if (at_beginning_of_minor_run_) {
text += reading_direction_is_ltr ? kLRM : kRLM;
}
text = it_->word()->BestUTF8(blob_index_, !reading_direction_is_ltr);
if (IsAtFinalSymbolOfWord()) AppendSuffixMarks(&text);
}
break;
}
int length = text.length() + 1;
char* result = new char[length];
strncpy(result, text.string(), length);
return result;
}
示例15: ParseAuth
bool ParseAuth(char* auth, MgHttpRequestParam* params)
{
bool bGotAuth = false;
////////////////////////////////////////////////////////////////////////////
//Bypass the standard authentication handling for OGC (WMS and WFS) requests.
//For these requests, use predefined credentials
//
// OGC requests do not use OPERATION= parameter...
STRING op = params->GetParameterValue(MgHttpResourceStrings::reqOperation);
if(op.length() == 0 && IsOgcRequest(params))
return AuthenticateOgcRequest(params);
////////////////////////////////////////////////////////////////////////////
const char* basic = MapAgentStrings::BasicAuth;
if (NULL != auth && NULL != strstr(auth, basic))
{
char* base64 = strstr(auth, basic) + strlen(basic);
unsigned long origLen = (unsigned long) strlen(base64);
unsigned long len = Base64::GetDecodedLength(origLen);
if (len < 128)
{
char buf[128];
memset(buf, 0, 128);
Base64::Decode((unsigned char*)buf, base64, origLen);
char* split = strchr(buf, ':'); // NOXLATE
if (NULL != split)
{
*split++ = '\0';
string username = buf;
string password = split;
params->AddParameter(MgHttpResourceStrings::reqUsername,
MgUtil::MultiByteToWideChar(username));
params->AddParameter(MgHttpResourceStrings::reqPassword,
MgUtil::MultiByteToWideChar(password));
bGotAuth = true;
}
}
}
return bGotAuth;
}