本文整理汇总了C++中AString::length方法的典型用法代码示例。如果您正苦于以下问题:C++ AString::length方法的具体用法?C++ AString::length怎么用?C++ AString::length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AString
的用法示例。
在下文中一共展示了AString::length方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetHTMLEscapedString
AString cWebAdmin::GetHTMLEscapedString(const AString & a_Input)
{
AString dst;
dst.reserve(a_Input.length());
// Loop over input and substitute HTML characters for their alternatives:
size_t len = a_Input.length();
for (size_t i = 0; i < len; i++)
{
switch (a_Input[i])
{
case '&': dst.append("&"); break;
case '\'': dst.append("'"); break;
case '"': dst.append("""); break;
case '<': dst.append("<"); break;
case '>': dst.append(">"); break;
default:
{
dst.push_back(a_Input[i]);
break;
}
} // switch (a_Input[i])
} // for i - a_Input[]
return dst;
}
示例2: Command
virtual bool Command(const AString & a_Command, const cPlugin * a_Plugin, const AString & a_Permission, const AString & a_HelpString) override
{
if (!a_HelpString.empty())
{
m_Commands.push_back(AStringPair(a_Command, a_HelpString));
if (m_MaxLen < a_Command.length())
{
m_MaxLen = a_Command.length();
}
}
return false;
}
示例3: FindTagByPath
int cParsedNBT::FindTagByPath(int a_Tag, const AString & a_Path) const
{
if (a_Tag < 0)
{
return -1;
}
size_t Begin = 0;
size_t Length = a_Path.length();
int Tag = a_Tag;
for (size_t i = 0; i < Length; i++)
{
if (a_Path[i] != '\\')
{
continue;
}
Tag = FindChildByName(Tag, a_Path.c_str() + Begin, i - Begin - 1);
if (Tag < 0)
{
return -1;
}
Begin = i + 1;
} // for i - a_Path[]
if (Begin < Length)
{
Tag = FindChildByName(Tag, a_Path.c_str() + Begin, Length - Begin);
}
return Tag;
}
示例4:
cCallback (const AString & a_PlayerName) :
m_BestRating(0),
m_NameLength(a_PlayerName.length()),
m_PlayerName(a_PlayerName),
m_BestMatch(),
m_NumMatches(0)
{}
示例5: sizeof
void cSHA1Checksum::DigestToJava(const Checksum & a_Digest, AString & a_Out)
{
Checksum Digest;
memcpy(Digest, a_Digest, sizeof(Digest));
bool IsNegative = (Digest[0] >= 0x80);
if (IsNegative)
{
// Two's complement:
bool carry = true; // Add one to the whole number
for (int i = 19; i >= 0; i--)
{
Digest[i] = ~Digest[i];
if (carry)
{
carry = (Digest[i] == 0xff);
Digest[i]++;
}
}
}
a_Out.clear();
a_Out.reserve(40);
for (int i = 0; i < 20; i++)
{
AppendPrintf(a_Out, "%02x", Digest[i]);
}
while ((a_Out.length() > 0) && (a_Out[0] == '0'))
{
a_Out.erase(0, 1);
}
if (IsNegative)
{
a_Out.insert(0, "-");
}
}
示例6: Error
void cSocketInputStream::Error(const AString & a_ErrorMsg)
{
send(m_Socket, a_ErrorMsg.c_str(), static_cast<int>(a_ErrorMsg.length()), 0);
static const char EndLine[] = "\n";
send(m_Socket, EndLine, sizeof(EndLine) - 1, 0);
}
示例7: DigestToJava
// Converts a raw 160-bit SHA1 digest into a Java Hex representation
// According to http://wiki.vg/wiki/index.php?title=Protocol_Encryption&oldid=2802
static void DigestToJava(byte a_Digest[20], AString & a_Out)
{
bool IsNegative = (a_Digest[0] >= 0x80);
if (IsNegative)
{
// Two's complement:
bool carry = true; // Add one to the whole number
for (int i = 19; i >= 0; i--)
{
a_Digest[i] = ~a_Digest[i];
if (carry)
{
carry = (a_Digest[i] == 0xff);
a_Digest[i]++;
}
}
}
a_Out.clear();
a_Out.reserve(40);
for (int i = 0; i < 20; i++)
{
AppendPrintf(a_Out, "%02x", a_Digest[i]);
}
while ((a_Out.length() > 0) && (a_Out[0] == '0'))
{
a_Out.erase(0, 1);
}
if (IsNegative)
{
a_Out.insert(0, "-");
}
}
示例8: GetOSErrorString
AString GetOSErrorString( int a_ErrNo)
{
char buffer[ 1024 ];
AString Out;
#ifdef _WIN32
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, a_ErrNo, 0, buffer, ARRAYCOUNT(buffer), NULL);
Printf(Out, "%d: %s", a_ErrNo, buffer);
if (!Out.empty() && (Out[Out.length() - 1] == '\n'))
{
Out.erase(Out.length() - 2);
}
return Out;
#else // _WIN32
// According to http://linux.die.net/man/3/strerror_r there are two versions of strerror_r():
#if !defined(__APPLE__) && ( _GNU_SOURCE) && !defined(ANDROID_NDK) // GNU version of strerror_r()
char * res = strerror_r( errno, buffer, ARRAYCOUNT(buffer));
if (res != NULL)
{
Printf(Out, "%d: %s", a_ErrNo, res);
return Out;
}
#else // XSI version of strerror_r():
int res = strerror_r( errno, buffer, ARRAYCOUNT(buffer));
if (res == 0)
{
Printf(Out, "%d: %s", a_ErrNo, buffer);
return Out;
}
#endif // strerror_r() version
else
{
Printf(Out, "Error %d while getting error string for error #%d!", errno, a_ErrNo);
return Out;
}
#endif // else _WIN32
}
示例9: BestMatch
cCallback (const AString & a_PlayerName, cPlayerListCallback & a_Callback)
: m_Callback( a_Callback )
, BestMatch( NULL )
, BestRating( 0 )
, NumMatches( 0 )
, NameLength( a_PlayerName.length() )
, PlayerName( a_PlayerName )
{}
示例10: CreateVerticalStrategyFromString
cPiece::cVerticalStrategyPtr CreateVerticalStrategyFromString(const AString & a_StrategyDesc, bool a_LogWarnings)
{
// Break apart the strategy class, the first parameter before the first pipe char:
auto idxPipe = a_StrategyDesc.find('|');
if (idxPipe == AString::npos)
{
idxPipe = a_StrategyDesc.length();
}
AString StrategyClass = a_StrategyDesc.substr(0, idxPipe);
// Create a strategy class based on the class string:
cPiece::cVerticalStrategyPtr Strategy;
if (NoCaseCompare(StrategyClass, "Fixed") == 0)
{
Strategy = std::make_shared<cVerticalStrategyFixed>();
}
else if (NoCaseCompare(StrategyClass, "Range") == 0)
{
Strategy = std::make_shared<cVerticalStrategyRange>();
}
else if (NoCaseCompare(StrategyClass, "TerrainTop") == 0)
{
Strategy = std::make_shared<cVerticalStrategyTerrainTop>();
}
else if (NoCaseCompare(StrategyClass, "TerrainOrOceanTop") == 0)
{
Strategy = std::make_shared<cVerticalStrategyTerrainOrOceanTop>();
}
else
{
return nullptr;
}
// Initialize the strategy's parameters:
AString Params;
if (idxPipe < a_StrategyDesc.length())
{
Params = a_StrategyDesc.substr(idxPipe + 1);
}
if (!Strategy->InitializeFromString(Params, a_LogWarnings))
{
return nullptr;
}
return Strategy;
}
示例11: SetOwner
void cMobHeadEntity::SetOwner(const AString & a_Owner)
{
if ((a_Owner.length() > 16) || (m_Type != SKULL_TYPE_PLAYER))
{
return;
}
m_Owner = a_Owner;
}
示例12: Printf
int cFile::Printf(const char * a_Fmt, ...)
{
AString buf;
va_list args;
va_start(args, a_Fmt);
AppendVPrintf(buf, a_Fmt, args);
va_end(args);
return Write(buf.c_str(), buf.length());
}
示例13: GetFolderContents
AStringVector cFile::GetFolderContents(const AString & a_Folder)
{
AStringVector AllFiles;
#ifdef _WIN32
// If the folder name doesn't contain the terminating slash / backslash, add it:
AString FileFilter = a_Folder;
if (
!FileFilter.empty() &&
(FileFilter[FileFilter.length() - 1] != '\\') &&
(FileFilter[FileFilter.length() - 1] != '/')
)
{
FileFilter.push_back('\\');
}
// Find all files / folders:
FileFilter.append("*.*");
HANDLE hFind;
WIN32_FIND_DATAA FindFileData;
if ((hFind = FindFirstFileA(FileFilter.c_str(), &FindFileData)) != INVALID_HANDLE_VALUE)
{
do
{
AllFiles.push_back(FindFileData.cFileName);
} while (FindNextFileA(hFind, &FindFileData));
FindClose(hFind);
}
#else // _WIN32
DIR * dp;
AString Folder = a_Folder;
if (Folder.empty())
{
Folder = ".";
}
if ((dp = opendir(Folder.c_str())) == nullptr)
{
LOGERROR("Error (%i) opening directory \"%s\"\n", errno, Folder.c_str());
}
else
{
struct dirent *dirp;
while ((dirp = readdir(dp)) != nullptr)
{
AllFiles.push_back(dirp->d_name);
}
closedir(dp);
}
#endif // else _WIN32
return AllFiles;
}
示例14: GetUUIDFileName
AString cPlayer::GetUUIDFileName(const AString & a_UUID)
{
AString UUID = cMojangAPI::MakeUUIDDashed(a_UUID);
ASSERT(UUID.length() == 36);
AString res("players/");
res.append(UUID, 0, 2);
res.push_back('/');
res.append(UUID, 2, AString::npos);
res.append(".json");
return res;
}
示例15: SetCustomName
void cMonster::SetCustomName(const AString & a_CustomName)
{
m_CustomName = a_CustomName;
// The maximal length is 64
if (a_CustomName.length() > 64)
{
m_CustomName = a_CustomName.substr(0, 64);
}
if (m_World != nullptr)
{
m_World->BroadcastEntityMetadata(*this);
}
}