本文整理汇总了C++中AString::getSize方法的典型用法代码示例。如果您正苦于以下问题:C++ AString::getSize方法的具体用法?C++ AString::getSize怎么用?C++ AString::getSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AString
的用法示例。
在下文中一共展示了AString::getSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: append
size_t AOutputBuffer::append(const AString& str, size_t len)
{
if (!len)
return 0;
if (AConstant::npos == len)
return _append(str.c_str(), str.getSize());
else
{
AASSERT(this, len <= str.getSize());
return _append(str.c_str(), len);
}
}
示例2: ut_ATextGenerator_General
int ut_ATextGenerator_General()
{
std::cerr << "ut_ATextGenerator_General" << std::endl;
int iRet = 0x0;
AString str;
bool errorOccured = false;
for (int iX=0; iX < 666; ++iX)
{
u4 sizeNeeded = ARandomNumberGenerator::get().nextRange(300, 16);
//std::cerr << "ATextGenerator::generateUniqueId size: " << sizeNeeded << std::endl;
ATextGenerator::generateUniqueId(str, sizeNeeded);
if (str.getSize() != sizeNeeded)
{
std::cerr << "ATextGenerator::generateUniqueId failed for size: " << sizeNeeded << std::endl;
iRet++;
errorOccured = true;
break;
}
str.clear();
}
if (!errorOccured)
std::cerr << "." << std::flush;
return iRet;
}
示例3: generateRandomString
void ATextGenerator::generateRandomString(AOutputBuffer& target, size_t len, const AString& strCharSet)
{
for (size_t i = 0x0; i < len; ++i)
{
target.append(strCharSet.peek(ARandomNumberGenerator::get().nextRange(strCharSet.getSize())));
}
}
示例4: _set
void AFragmentCounter::_set()
{
u1 digits = (u1)(log10((float)m_Value) + 1);
u1 odosize = (digits > m_Digits ? digits : m_Digits);
m_strOdometer.fill('0');
AString str;
str.parseU4(m_Value);
if (m_strOdometer.getSize() < str.getSize())
m_strOdometer.setSize(str.getSize());
str.reverse();
memcpy(m_strOdometer.startUsingCharPtr(), str.c_str(), str.getSize());
m_strOdometer.stopUsingCharPtr(odosize);
m_strOdometer.reverse();
}
示例5: splitSyllables
int AWordUtility::splitSyllables(const AString& source, VECTOR_AString& result, bool handleSilentTrailing /* = true */)
{
if (source.isEmpty())
return 0;
AString word(source);
if (handleSilentTrailing)
word.stripTrailing(msstr_SilentEnd);
int count = 0;
size_t start = 0;
size_t pos = word.findOneOf(msstr_SyllableSeparators);
while (AConstant::npos != pos)
{
AString str;
word.peek(str, start, pos - start + 1);
result.push_back(str.c_str());
++count;
start = pos+1;
pos = word.findNotOneOf(msstr_SyllableSeparators, start);
if (AConstant::npos != pos)
pos = word.findOneOf(msstr_SyllableSeparators, start);
}
if (start < word.getSize())
{
//a_Append leftovers to last word
AString str;
word.peek(str, start);
if (count > 0)
result.back().append(str);
else
result.push_back(str);
}
//a_Account for the silent trailing letters
if (handleSilentTrailing && word.getSize() < source.getSize())
{
AString str;
source.peek(str, word.getSize());
if (count > 0)
result.back().append(str);
else
result.push_back(str);
}
return count;
}
示例6: alibrary_Objects_Model_emitContentFromPath
/*!
Uses the model to emit content for a path
thisfunction("<path to the AXmlElement to emit>", separate)
lua namespace: model
lua param: Path to emit
lua param: if non-nil then each element found will be returned by itself
lua return: Content at the given path or nil if element does not exist
*/
static int alibrary_Objects_Model_emitContentFromPath(lua_State *L)
{
ATemplateContext *pLuaContext = static_cast<ATemplateContext *>(L->acontext);
AASSERT(NULL, pLuaContext);
size_t len = AConstant::npos;
const char *s = luaL_checklstring(L, 1, &len);
const AString& xmlpath = AString::wrap(s, len);
int mode = 0;
if (lua_gettop(L) > 1)
mode = luaL_checkint(L, 2);
AXmlElement::CONST_CONTAINER nodes;
size_t ret = pLuaContext->useModel().useRoot().find(xmlpath, nodes);
if (mode)
{
//a_Return each as separate values
AString str;
for (AXmlElement::CONST_CONTAINER::const_iterator cit = nodes.begin(); cit != nodes.end(); ++cit)
{
(*cit)->emitContent(str);
lua_pushlstring(L, str.c_str(), str.getSize());
str.clear();
}
return (int)ret;
}
else
{
if (ret > 0)
{
//a_Return content concatinated
ARope rope;
for (AXmlElement::CONST_CONTAINER::const_iterator cit = nodes.begin(); cit != nodes.end(); ++cit)
(*cit)->emitContent(rope);
const AString& str = rope.toAString();
lua_pushlstring(L, str.c_str(), str.getSize());
return 1;
}
else
return 0;
}
}
示例7: alibrary_Objects_Model_emitJson
/*!
Emits the entire model as JSON
thisfunction([indent = -1])
lua namespace: model
lua param: (Optional) if 0 or greater, will indent the output. Default -1 will inline it.
lua return: JSON string of default AXmlDocument model
*/
static int alibrary_Objects_Model_emitJson(lua_State *L)
{
ATemplateContext *pLuaContext = static_cast<ATemplateContext *>(L->acontext);
AASSERT(NULL, pLuaContext);
int indent = -1;
if (lua_gettop(L) > 0)
{
indent = luaL_checkint(L, 1);
}
AString str;
pLuaContext->useModel().useRoot().emitJson(str, indent);
lua_pushlstring(L, str.c_str(), str.getSize());
return 1;
}
示例8: alibrary_Objects_Model_getText
/*!
Gets text value for a given path
thisfunction("element path")
lua param: Element path
lua return: Text content for a given element or nil if it doesn't exist
*/
static int alibrary_Objects_Model_getText(lua_State *L)
{
ATemplateContext *pLuaContext = static_cast<ATemplateContext *>(L->acontext);
AASSERT(NULL, pLuaContext);
size_t len = AConstant::npos;
const char *s = luaL_checklstring(L, 1, &len);
const AString& xmlpath = AString::wrap(s, len);
AXmlElement *pElement = pLuaContext->useModel().useRoot().findElement(xmlpath);
if (!pElement)
{
return 0;
}
else
{
AString str;
pElement->emitContent(str);
lua_pushlstring(L, str.c_str(), str.getSize());
return 1;
}
}
示例9: generateFromTemplate
void ATextGenerator::generateFromTemplate(AOutputBuffer& target, const AString &strTemplate)
{
if (strTemplate.isEmpty())
return;
//a_If the last is % and one before is not %, then expansion error will occur
size_t end = strTemplate.getSize();
if (strTemplate[end - 1] == '%')
{
if (end < 1)
{
//a_Force early termination
end = 0;
}
else
if (strTemplate[end - 2] != '%')
{
end--;
}
}
char cEscape;
for (size_t x = 0; x < end; ++x)
{
cEscape = strTemplate[x];
if (cEscape == '%')
{
if (++x >= end)
break;
switch(strTemplate[x])
{
case '%' : break;
case 'z' :
target.append(AString::fromInt(si_Counter++));
cEscape = '\x0';
break;
case 'n' :
cEscape = generateRandomNumeral();
break;
case 'N' :
if (ARandomNumberGenerator::get().nextRange(100) >= 50)
cEscape = '+';
else
cEscape = '-';
break;
case 'l' :
cEscape = generateRandomLowercaseLetter();
break;
case 'L' :
cEscape = generateRandomUppercaseLetter();
break;
case 'r' :
cEscape = (char)(ARandomNumberGenerator::get().nextRange(255) + 0x1);
break;
case 'R' :
cEscape = ARandomNumberGenerator::get().nextU1();
break;
case 's' :
cEscape = generateRandomUppercaseLetter();
if (ARandomNumberGenerator::get().nextRange(100) >= 50)
cEscape = (char)tolower(cEscape);
break;
case 't' :
ATime().emitYYYYMMDDHHMMSS(target);
cEscape = '\x0';
break;
case 'T' :
ATime().emitRFCtime(target);
cEscape = '\x0';
break;
default :
//a_Escape character detected, but no valid control character found
target.append(cEscape); //a_Keep the sequence untouched
cEscape = strTemplate[x]; //a_Current char becomes escape to stay consistent with the add to follow
}
}
if (cEscape != '\x0')
target.append(cEscape);
}
}
示例10: getSoundexForm
void AWordUtility::getSoundexForm(const AString& source, AString& result, size_t minSize)
{
result.clear();
if (source.isEmpty())
return;
//a_First character appended as is
AString str(source);
str.makeLower();
size_t sourceSize = str.getSize();
size_t pos = 0;
while (pos < sourceSize)
{
switch(str.at(pos))
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'h':
case 'w':
case 'y':
break;
//---
case 'p':
if (pos == 0 && sourceSize > 2)
{
if ('s' == str.at(pos+1))
{
break; //a_ps => s at word start
}
else if ('h' == str.at(pos+1))
{
++pos; //a_pf => f, fallthrough
}
}
case 'b':
case 'f':
case 'v':
if (!result.isEmpty())
{
if (str.at(pos) != result.at(result.getSize()-1))
result.append('1');
}
else
result.append('1');
break;
//---
case 'd':
if (pos+1 < sourceSize)
{
if ('g' == str.at(pos+1))
break; //a_dg => g
} //a_Fallthough from d to t
case 't':
if (pos+1 < sourceSize && 'c' == str.at(pos+1))
{
if (pos+2 < sourceSize && 'h' == str.at(pos+2))
{
++pos;
break; //a_tch => ch
}
}
if (!result.isEmpty())
{
if (str.at(pos) != result.at(result.getSize()-1))
result.append('3');
}
else
result.append('3');
break;
//---
case 'g':
if (pos+1 < sourceSize)
{
if ('h' == str.at(pos+1))
{
if (pos+2 < sourceSize)
{
if ('t' == str.at(pos+2))
{
++pos;
break; //a_ght => t
}
else
break; //a_gh => h
}
}
else if ('n' == str.at(pos+1))
{
break; //a_gn => n
}
} //a_Fallthrough
case 'k':
if (pos+1 < sourceSize && 'n' == str.at(pos+1))
{
break; //a_kn => n
//.........这里部分代码省略.........
示例11: getPlural
void AWordUtility::getPlural(const AString& one, AString& many)
{
many.clear();
//a_Words of size 1 or 2, just append s and return
if (one.getSize() < 3)
{
many.assign(one);
many.append('s');
return;
}
switch(one.last())
{
case 's':
{
char c = one.at(one.getSize()-2);
if ('i' == c)
{
//a_"is" -> "es"
many.assign(one);
many.set('i', many.getSize()-2);
}
else if ('u' == c)
{
//a_"us" -> "ii"
one.peek(many, 0, one.getSize()-2);
many.append("ii", 2);
}
else
{
many.assign(one);
many.append("es", 2);
}
}
break;
case 'z':
case 'x':
many.assign(one);
many.append("es", 2);
break;
case 'h':
{
char c = one.at(one.getSize()-2);
if ('s' == c || 'c' == c)
{
many.assign(one);
many.append("es", 2);
}
else
{
many.assign(one);
many.append('s');
}
}
break;
case 'y':
{
char c = one.at(one.getSize()-2);
if (AConstant::npos != sstr_Vowels.find(c))
{
//a_vowel+'y', add 's'
many.assign(one);
many.append('s');
}
else
{
//a_consonant+'y', convert 'y' to 'ies'
one.peek(many, 0, one.getSize()-1);
many.append("ies", 3);
}
}
break;
default:
many.assign(one);
many.append('s');
break;
}
}
示例12: getPhoneticForm
/*
Sound conversions
Pre-process
Before After
ght t
Process ending
Before After
e (remove)
es s
ie i
ies s
ng n
y i
eau o
Process
Before After
ch C
ck k
ea I
gh g
gn n
ie i
kh k
kn n
ks x
mb m
nc nk
oo U
ou u
ph f
ps s
q(~u) k (q without u)
qu kw
sh S
tia Sa
th Z
wh w
ugh f
zh Z
Post-process (@-any vowel)
[email protected] [email protected]
Phonetics:
ch = C (chair = Cair)
sh = S (bash = baS)
zh = Z (zhivago = Zivago)
oo = U (boot = bUt)
*/
void AWordUtility::getPhoneticForm(const AString& source, AString& result)
{
AString work(source);
work.makeLower();
const char IGNORE_CHAR = '_';
result.clear();
size_t workSize = work.getSize();
if (!workSize)
return;
//a_STEP 1
//a_Preprocess (before and after data must be same size)
//a_These replacements take precedence
int i;
const int iiPreCount = 1;
const AString preBefore[iiPreCount] = { "ght" };
const AString preAfter[iiPreCount] = { "t__" };
for (i=0; i<iiPreCount; ++i)
work.replace(preBefore[i], preAfter[i]);
//a_STEP 2
//a_Ending (data in reverse) (before and after data must be same size)
const int iiEndingCount = 9;
const AString endBefore[iiEndingCount] = { "e", "se", "sei", "ei", "yc", "gn", "uae", "y", "eu" };
const AString endAfter[iiEndingCount] = { "_", "s_", "s_i", "_i", "is", "_n", "__o", "i", "_i" };
work.reverse();
for (i=0; i<iiEndingCount; ++i)
{
if (0 == work.find(endBefore[i]))
{
work.overwrite(0, endAfter[i]);
}
}
work.reverse();
//a_STEP 4
//a_Iterate and process sounds
AString temp;
u4 pos = 0;
while(pos < workSize)
{
switch(work.at(pos))
{
//a_ ch->C
case 'c':
if ('h' == work.at(pos+1, '\x0'))
//.........这里部分代码省略.........
示例13: str
void ATemplateNodeHandler_DADA::Node::_appendVariable(ADadaDataHolder *pddh, MAP_AString_AString& globals, const AString& strType, AOutputBuffer& target)
{
AASSERT(this, strType.getSize() > 0);
AString strTypeName, strControl;
LIST_AString listControlNames;
size_t pos = strType.find(':');
if (AConstant::npos != pos)
{
strType.peek(strTypeName, 0, pos);
strTypeName.makeLower();
strType.peek(strControl, pos+1);
strControl.makeLower();
strControl.split(listControlNames, ',', AConstant::ASTRING_WHITESPACE);
}
else
{
strTypeName.assign(strType);
strTypeName.makeLower();
}
//a_Find it in the global lookup
MAP_AString_AString::iterator it = globals.find(strTypeName);
if (it != globals.end())
{
AString str((*it).second);
LIST_AString::iterator itN = listControlNames.begin();
while (itN != listControlNames.end())
{
if (!(*itN).compare("article", 7))
{
AString strTemp(str);
if (AConstant::npos == AWordUtility::sstr_Vowels.find(str.at(0)))
{
str.assign("a ", 2);
}
else
{
str.assign("an ", 3);
}
str.append(strTemp);
}
if (!(*itN).compare("plural", 6))
{
AString strTemp;
AWordUtility::getPlural(str, strTemp);
str.assign(strTemp);
}
if (!(*itN).compare("uppercase", 9))
{
str.makeUpper();
}
if (!(*itN).compare("lowercase", 9))
{
str.makeLower();
}
if (!(*itN).compare("proper", 6))
{
str.use(0) = (u1)toupper(str.at(0));
size_t nextStart;
size_t nextSpace = str.find(' ', 1);
while (AConstant::npos != nextSpace)
{
nextStart = nextSpace + 1;
if (nextStart < str.getSize())
str.use(nextStart) = (u1)toupper(str.at(nextStart));
else
break;
nextSpace = str.find(' ', nextStart);
}
}
++itN;
}
target.append(str);
}
else
{
//a_Not found in global map
}
}
示例14: parse
size_t AFragmentString::parse(const AString& str)
{
size_t iRet = AConstant::npos;
size_t iX = 0;
AString strHold;
while(iX < str.getSize())
{
switch(str[iX])
{
case '\\' :
{
++iX;
if (str.getSize() > iX)
{
strHold += str[iX];
iRet = iX;
}
else
{
//a_String truncated
iRet = iX - 1;
return iRet;
}
}
break;
case '(' :
{
iX++;
if (str.getSize() > iX)
{
size_t iF = str.find(')', iX+1);
if (iF != AConstant::npos)
{
AASSERT(this, iF >= iX);
if (!strHold.isEmpty()) { m_Container.push_back(new AFragmentConstant(strHold)); strHold.clear(); iRet = iX-1; }
AString strT;
str.peek(strT, iX, iF-iX);
iX = iF; // advance offset after extraction
u1 b;
u4 n[2];
b = (u1)strT.toInt();
if (b > 9)
b = 9;
if ((iF = strT.find(',')) == AConstant::npos)
{
// Only 1 number, the digit value
long stop = 10;
for (int i=1; i<b; ++i)
stop *= 10;
m_Container.push_back(new AFragmentCounter(b, u4(stop-1)));
}
else
{
AString str1;
strT.peek(str1, iF + 1);
if ((iF = str1.find(',')) == AConstant::npos)
{
n[0] = str1.toU4();
m_Container.push_back(new AFragmentCounter(b, n[0]));
}
else
{
AString strQ;
str1.peek(strQ, 0, iF);
n[0] = strQ.toU4();
strQ.clear();
str1.peek(strQ, iF+1);
n[1] = strQ.toU4();
if ((iF = str1.find(',', iF+1)) == AConstant::npos)
m_Container.push_back(new AFragmentCounter(b, n[0], n[1]));
else {
strQ.clear();
str1.peek(strQ, iF+1);
m_Container.push_back(new AFragmentCounter(b, n[0], n[1], strQ.toInt()));
}
}
}
iRet = iX;
}
else
{
//a_Closing tag not found
iRet = iX-1;
return iRet;
}
}
else
{
//a_String is truncated
iRet = iX-1;
return iRet;
}
}
break;
case '{' :
{
//.........这里部分代码省略.........
示例15: execute
AOSContext::ReturnCode AOSOutput_Template::execute(AOSContext& context)
{
//a_See if extension for mime type set for the template(s)
AString ext;
if (context.getOutputParams().emitContentFromPath(AOS_BaseModules_Constants::MIME_EXTENSION, ext))
{
m_Services.useConfiguration().setMimeTypeFromExt(ext, context);
}
else
{
//a_Set content type based on request URL extension
m_Services.useConfiguration().setMimeTypeFromExt(context.useRequestUrl().getExtension(), context);
}
// Iterate parameters and build the template
const AXmlElement::CONTAINER& container = context.getOutputParams().getContentContainer();
for (AXmlElement::CONTAINER::const_iterator cit = container.begin(); cit != container.end(); ++cit)
{
//a_Check "if" condition
AString ifElement;
if ((*cit)->getAttributes().get(ASW("if",2), ifElement))
{
if (ifElement.getSize() > 0)
{
//a_Check condition, if not met continue with next template
if (!context.useModel().exists(ifElement))
{
if (context.useEventVisitor().isLogging(AEventVisitor::EL_DEBUG))
context.useEventVisitor().startEvent(ARope("Skipping conditional file template IF ")+ifElement, AEventVisitor::EL_DEBUG);
continue;
}
}
}
//a_Check "ifnot" condition
ifElement.clear();
if ((*cit)->getAttributes().get(ASW("ifnot",5), ifElement))
{
if (ifElement.getSize() > 0)
{
//a_Check condition, if not met continue with next template
if (context.useModel().exists(ifElement))
{
if (context.useEventVisitor().isLogging(AEventVisitor::EL_DEBUG))
context.useEventVisitor().startEvent(ARope("Skipping conditional file template IFNOT ")+ifElement, AEventVisitor::EL_DEBUG);
continue;
}
}
}
//
// Now we check if this is inlined or filename
//
AString str(1024, 512);
if ((*cit)->getName().equals(AOS_BaseModules_Constants::TEMPLATE))
{
if (context.useEventVisitor().isLoggingDebug())
{
context.useEventVisitor().startEvent(getClass() + ": Creating new inline template", AEventVisitor::EL_DEBUG);
}
// Create a new template
AAutoPtr<ATemplate> pTemplate(m_Services.createTemplate(), true);
// Add inline template
str.clear();
(*cit)->emitContent(str);
AFile_AString strfile(str);
pTemplate->clear();
pTemplate->fromAFile(strfile);
pTemplate->process(context.useLuaTemplateContext(), context.useOutputBuffer());
}
else if ((*cit)->getName().equals(AOS_BaseModules_Constants::FILENAME))
{
// Add filename based template
AFilename filename(m_Services.useConfiguration().getAosBaseDataDirectory());
str.clear();
(*cit)->emitContent(str);
filename.join(str, false);
if (context.useEventVisitor().isLoggingDebug())
{
context.useEventVisitor().startEvent(getClass()+": Fetching/parsing template for: "+filename, AEventVisitor::EL_DEBUG);
}
AAutoPtr<ATemplate> pT(NULL, false);
if (ACacheInterface::NOT_FOUND == m_Services.useCacheManager().getTemplate(context, filename, pT))
{
//a_Not found add error and continue
if (context.useEventVisitor().isLogging(AEventVisitor::EL_WARN))
context.useEventVisitor().startEvent(ARope(getClass())+ASWNL(": Unable to find a template file: ")+filename+ASWNL(", ignoring and continuing"), AEventVisitor::EL_WARN);
continue;
}
//a_Parse template
if (context.useEventVisitor().isLogging(AEventVisitor::EL_DEBUG))
{
context.useEventVisitor().startEvent(getClass()+"Processing template file: "+filename, AEventVisitor::EL_DEBUG);
}
AASSERT(this, pT.isNotNull());
pT->process(context.useLuaTemplateContext(), context.useOutputBuffer());
}
}
//.........这里部分代码省略.........