本文整理汇总了C++中AString::substr方法的典型用法代码示例。如果您正苦于以下问题:C++ AString::substr方法的具体用法?C++ AString::substr怎么用?C++ AString::substr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AString
的用法示例。
在下文中一共展示了AString::substr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadFromString
bool cPrefabPiecePool::LoadFromString(const AString & a_Contents, const AString & a_FileName, bool a_LogWarnings)
{
// If the contents start with GZip signature, ungzip and retry:
if (a_Contents.substr(0, 3) == "\x1f\x8b\x08")
{
AString Uncompressed;
auto res = UncompressStringGZIP(a_Contents.data(), a_Contents.size(), Uncompressed);
if (res == Z_OK)
{
return LoadFromString(Uncompressed, a_FileName, a_LogWarnings);
}
else
{
CONDWARNING(a_LogWarnings, "Failed to decompress Gzip data in file %s: %d", a_FileName.c_str(), res);
return false;
}
}
// Search the first 8 KiB of the file for the format auto-detection string:
auto Header = a_Contents.substr(0, 8192);
if (Header.find("CubesetFormatVersion =") != AString::npos)
{
return LoadFromCubeset(a_Contents, a_FileName, a_LogWarnings);
}
CONDWARNING(a_LogWarnings, "Cannot load prefabs from file %s, unknown file format", a_FileName.c_str());
return false;
}
示例2: StringToItem
bool StringToItem(const AString & a_ItemTypeString, cItem & a_Item)
{
AString ItemName = TrimString(a_ItemTypeString);
if (ItemName.substr(0, 10) == "minecraft:")
{
ItemName = ItemName.substr(10);
}
return gsBlockIDMap.ResolveItem(ItemName, a_Item);
}
示例3: CreateDir
Bool HawkOSOperator::CreateDir(const AString& sDir)
{
if (!sDir.size())
return true;
AString sSysDir = sDir;
HawkStringUtil::Replace<AString>(sSysDir,"\\","/");
Size_t iPos = sSysDir.rfind('/');
if (iPos != AString::npos)
{
AString sParent = sSysDir.substr(0, iPos);
if (sParent.size() && !ExistFolder(sParent))
CreateDir(sParent);
}
#ifdef PLATFORM_WINDOWS
if (_mkdir(sSysDir.c_str()) != HAWK_OK && errno != EEXIST)
return false;
#else
mode_t iMask = umask(0);
if (mkdir(sSysDir.c_str(), S_IRWXU|S_IRWXG|S_IXOTH|S_IROTH) != HAWK_OK && errno != EEXIST)
{
umask(iMask);
return false;
}
umask(iMask);
#endif
return true;
}
示例4: 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;
}
示例5: SplitFilePath
AString HawkOSOperator::SplitFilePath(const AString& sFile)
{
AString sTmpFile = sFile;
HawkStringUtil::Replace<AString>(sTmpFile,"\\","/");
Int32 iPos = (Int32)sTmpFile.find_last_of('/');
if (iPos > 0)
{
return sTmpFile.substr(0,iPos+1);
}
return sTmpFile;
}
示例6: OnHeaderLine
void cHTTPRequest::OnHeaderLine(const AString & a_Key, const AString & a_Value)
{
if (
(NoCaseCompare(a_Key, "Authorization") == 0) &&
(strncmp(a_Value.c_str(), "Basic ", 6) == 0)
)
{
AString UserPass = Base64Decode(a_Value.substr(6));
size_t idxCol = UserPass.find(':');
if (idxCol != AString::npos)
{
m_AuthUsername = UserPass.substr(0, idxCol);
m_AuthPassword = UserPass.substr(idxCol + 1);
m_HasAuth = true;
}
}
if ((a_Key == "Connection") && (NoCaseCompare(a_Value, "keep-alive") == 0))
{
m_AllowKeepAlive = true;
}
AddHeader(a_Key, a_Value);
}
示例7: 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);
}
}
示例8: RemoveBom
void cIniFile::RemoveBom(AString & a_line) const
{
// The BOM sequence for UTF-8 is 0xEF, 0xBB, 0xBF
static unsigned const char BOM[] = { 0xEF, 0xBB, 0xBF };
// The BOM sequence, if present, is always th e first three characters of the input.
const AString ref = a_line.substr(0, 3);
// If any of the first three chars do not match, return and do nothing.
for (size_t i = 0; i < 3; ++i)
{
if (static_cast<unsigned char>(ref[i]) != BOM[i])
{
return;
}
}
// First three characters match; erase them.
a_line.erase(0, 3);
}
示例9: CreateFolderRecursive
bool cFile::CreateFolderRecursive(const AString & a_FolderPath)
{
// Special case: Fail if the path is empty
if (a_FolderPath.empty())
{
return false;
}
// Go through each path element and create the folder:
auto len = a_FolderPath.length();
auto PathSep = GetPathSeparator()[0];
for (decltype(len) i = 0; i < len; i++)
{
if (a_FolderPath[i] == PathSep)
{
CreateFolder(a_FolderPath.substr(0, i));
}
}
CreateFolder(a_FolderPath);
// Check the result by querying whether the final path exists:
return IsFolder(a_FolderPath);
}
示例10: FindFiles
/** 查找指定的文件
@Param 存储文件信息的列表
@Param 用于匹配文件名的字符
@Param 遍历时是否递归
@Param 是否遍历目录
*/
void FZipFilePack::FindFiles( VFileInfoList& fileList,const AString& pattern,
bool bRecurse,bool bDir )
{
VFileInfoList::iterator itr;
VFileInfoList::iterator end = m_FileInfos.end();
// 如果要查找的字符包含目录,则做一个全匹配
bool full_match = (pattern.find('/') != AString::npos ||
pattern.find('\\') != AString::npos );
// 获取关键字的目录
AString directory;
if( full_match )
{
size_t pos1 = pattern.rfind( '/' );
size_t pos2 = pattern.rfind( '\\' );
if( pos1 == AString::npos || ((pos2 != AString::npos) && pos1 < pos2) )
pos1 = pos2;
if( pos1 != AString::npos )
directory = pattern.substr( 0,pos1+1 );
}
// 遍历文件信息
for( itr=m_FileInfos.begin();itr!=end;itr++ )
{
if( ((itr->nCompressedSize != (size_t)-1) ||
(itr->nCompressedSize == (size_t)-1 && bDir)) &&
(bRecurse || itr->sPath == directory) )
{
if( AStringUtil::Match(full_match ? itr->sFileName : itr->sBaseName,pattern) )
fileList.push_back( *itr );
}
}
}
示例11: ParseText
void cCompositeChat::ParseText(const AString & a_ParseText)
{
size_t len = a_ParseText.length();
size_t first = 0; // First character of the currently parsed block
AString CurrentStyle;
AString CurrentText;
for (size_t i = 0; i < len; i++)
{
switch (a_ParseText[i])
{
case '@':
{
// Color code
i++;
if (i >= len)
{
// Not enough following text
break;
}
if (a_ParseText[i] == '@')
{
// "@@" escape, just put a "@" into the current text and keep parsing as text
if (i > first + 1)
{
CurrentText.append(a_ParseText.c_str() + first, i - first - 1);
}
first = i + 1;
continue;
}
else
{
// True color code. Create a part for the CurrentText and start parsing anew:
if (i >= first)
{
CurrentText.append(a_ParseText.c_str() + first, i - first - 1);
first = i + 1;
}
if (!CurrentText.empty())
{
m_Parts.push_back(new cTextPart(CurrentText, CurrentStyle));
CurrentText.clear();
}
AddStyle(CurrentStyle, a_ParseText.substr(i - 1, 2));
}
break;
}
case ':':
{
const char * LinkPrefixes[] =
{
"http",
"https"
};
for (size_t Prefix = 0; Prefix < ARRAYCOUNT(LinkPrefixes); Prefix++)
{
size_t PrefixLen = strlen(LinkPrefixes[Prefix]);
if (
(i >= first + PrefixLen) && // There is enough space in front of the colon for the prefix
(strncmp(a_ParseText.c_str() + i - PrefixLen, LinkPrefixes[Prefix], PrefixLen) == 0) // the prefix matches
)
{
// Add everything before this as a text part:
if (i > first + PrefixLen)
{
CurrentText.append(a_ParseText.c_str() + first, i - first - PrefixLen);
first = i - PrefixLen;
}
if (!CurrentText.empty())
{
AddTextPart(CurrentText, CurrentStyle);
CurrentText.clear();
}
// Go till the last non-whitespace char in the text:
for (; i < len; i++)
{
if (isspace(a_ParseText[i]))
{
break;
}
}
AddUrlPart(a_ParseText.substr(first, i - first), a_ParseText.substr(first, i - first), CurrentStyle);
first = i;
break;
}
} // for Prefix - LinkPrefix[]
break;
} // case ':'
} // switch (a_ParseText[i])
} // for i - a_ParseText[]
if (first < len)
{
AddTextPart(a_ParseText.substr(first, len - first), CurrentStyle);
}
}
示例12: ReadFile
bool cIniFile::ReadFile(const AString & a_FileName, bool a_AllowExampleRedirect)
{
m_Filename = a_FileName;
// Normally you would use ifstream, but the SGI CC compiler has
// a few bugs with ifstream. So ... fstream used.
fstream f;
AString line;
AString keyname, valuename, value;
AString::size_type pLeft, pRight;
bool IsFromExampleRedirect = false;
f.open((FILE_IO_PREFIX + a_FileName).c_str(), ios::in);
if (f.fail())
{
f.clear();
if (a_AllowExampleRedirect)
{
// Retry with the .example.ini file instead of .ini:
AString ExPath(a_FileName.substr(0, a_FileName.length() - 4));
ExPath.append(".example.ini");
f.open((FILE_IO_PREFIX + ExPath).c_str(), ios::in);
if (f.fail())
{
return false;
}
IsFromExampleRedirect = true;
}
else
{
return false;
}
}
bool IsFirstLine = true;
while (getline(f, line))
{
// To be compatible with Win32, check for existence of '\r'.
// Win32 files have the '\r' and Unix files don't at the end of a line.
// Note that the '\r' will be written to INI files from
// Unix so that the created INI file can be read under Win32
// without change.
// Removes UTF-8 Byte Order Markers (BOM) if, present.
if (IsFirstLine)
{
RemoveBom(line);
IsFirstLine = false;
}
size_t lineLength = line.length();
if (lineLength == 0)
{
continue;
}
if (line[lineLength - 1] == '\r')
{
line = line.substr(0, lineLength - 1);
}
if (line.length() == 0)
{
continue;
}
// Check that the user hasn't opened a binary file by checking the first
// character of each line!
if (!isprint(line[0]))
{
printf("%s: Binary-check failed on char %d\n", __FUNCTION__, line[0]);
f.close();
return false;
}
if ((pLeft = line.find_first_of(";#[=")) == AString::npos)
{
continue;
}
switch (line[pLeft])
{
case '[':
{
if (
((pRight = line.find_last_of("]")) != AString::npos) &&
(pRight > pLeft)
)
{
keyname = line.substr(pLeft + 1, pRight - pLeft - 1);
AddKeyName(keyname);
}
break;
}
case '=':
{
valuename = line.substr(0, pLeft);
value = line.substr(pLeft + 1);
//.........这里部分代码省略.........
示例13: LoadWorlds
//.........这里部分代码省略.........
a_Settings.AddValue("Worlds", "World", "world_nether");
a_Settings.AddValue("Worlds", "World", "world_end");
Worlds = a_Settings.GetValues("Worlds"); // Refresh the Worlds list so that the rest of the function works as usual
LOG("The server detected an old default config with bad world linkages. This has been autofixed by adding \"world_nether\" and \"world_end\" to settings.ini");
}
}
}
}
// Then load the other worlds
if (Worlds.size() <= 0)
{
return;
}
/* Here are the world creation rules. Note that these only apply for a world which is in settings.ini but has no world.ini file.
If an ini file is present, it overrides the world linkages and the dimension type in cWorld::start()
The creation rules are as follows:
- If a world exists in settings.ini but has no world.ini, then:
- If the world name is x_nether, create a world.ini with the dimension type "nether".
- If a world called x exists, set it as x_nether's overworld.
- Otherwise set the default world as x_nether's overworld.
- If the world name is x_end, create a world.ini with the dimension type "end".
- If a world called x exists, set it as x_end's overworld.
- Otherwise set the default world as x_end's overworld.
- If the world name is x (and doesn't end with _end or _nether)
- Create a world.ini with a dimension type of "overworld".
- If a world called x_nether exists, set it as x's nether world.
- Otherwise set x's nether world to blank.h
- If a world called x_end exists, set it as x's end world.
- Otherwise set x's nether world to blank.
*/
bool FoundAdditionalWorlds = false;
for (auto WorldNameValue : Worlds)
{
AString ValueName = WorldNameValue.first;
if (ValueName.compare("World") != 0)
{
continue;
}
AString WorldName = WorldNameValue.second;
if (WorldName.empty())
{
continue;
}
FoundAdditionalWorlds = true;
cWorld * NewWorld;
AString LowercaseName = StrToLower(WorldName);
AString NetherAppend="_nether";
AString EndAppend="_end";
// if the world is called x_nether
if ((LowercaseName.size() > NetherAppend.size()) && (LowercaseName.substr(LowercaseName.size() - NetherAppend.size()) == NetherAppend))
{
// The world is called x_nether, see if a world called x exists. If yes, choose it as the linked world,
// otherwise, choose the default world as the linked world.
// As before, any ini settings will completely override this if an ini is already present.
AString LinkTo = WorldName.substr(0, WorldName.size() - NetherAppend.size());
if (GetWorld(LinkTo) == nullptr)
{
LinkTo = DefaultWorldName;
}
NewWorld = new cWorld(WorldName.c_str(), dimNether, LinkTo);
}
// if the world is called x_end
else if ((LowercaseName.size() > EndAppend.size()) && (LowercaseName.substr(LowercaseName.size() - EndAppend.size()) == EndAppend))
{
// The world is called x_end, see if a world called x exists. If yes, choose it as the linked world,
// otherwise, choose the default world as the linked world.
// As before, any ini settings will completely override this if an ini is already present.
AString LinkTo = WorldName.substr(0, WorldName.size() - EndAppend.size());
if (GetWorld(LinkTo) == nullptr)
{
LinkTo = DefaultWorldName;
}
NewWorld = new cWorld(WorldName.c_str(), dimEnd, LinkTo);
}
else
{
NewWorld = new cWorld(WorldName.c_str());
}
m_WorldsByName[WorldName] = NewWorld;
} // for i - Worlds
if (!FoundAdditionalWorlds)
{
if (a_Settings.GetKeyComment("Worlds", 0) != " World=secondworld")
{
a_Settings.DeleteKeyComment("Worlds", 0);
a_Settings.AddKeyComment("Worlds", " World=secondworld");
}
}
}
示例14: if
UniquePtr<cPrefab> cPrefabPiecePool::LoadPrefabFromCubesetVer1(
const AString & a_FileName,
cLuaState & a_LuaState,
const AString & a_PieceName,
bool a_LogWarnings
)
{
// First try loading a referenced schematic file, if any:
AString SchematicFileName;
if (a_LuaState.GetNamedValue("SchematicFileName", SchematicFileName))
{
auto PathEnd = a_FileName.find_last_of("/\\"); // Find the last path separator
if (PathEnd != AString::npos)
{
SchematicFileName = a_FileName.substr(0, PathEnd) + SchematicFileName;
}
cBlockArea area;
if (!cSchematicFileSerializer::LoadFromSchematicFile(area, SchematicFileName))
{
CONDWARNING(a_LogWarnings, "Cannot load schematic file \"%s\" for piece %s in cubeset %s.",
SchematicFileName.c_str(), a_PieceName.c_str(), a_FileName.c_str()
);
return nullptr;
}
return cpp14::make_unique<cPrefab>(area);
} // if (SchematicFileName)
// There's no referenced schematic file, load from BlockDefinitions / BlockData.
// Get references to the data and the table.concat function:
cLuaState::cRef TableConcat, BlockDefinitions, BlockData;
if (
!a_LuaState.GetNamedGlobal("table.concat", TableConcat) ||
!a_LuaState.GetNamedValue("BlockDefinitions", BlockDefinitions) ||
!a_LuaState.GetNamedValue("BlockData", BlockData)
)
{
CONDWARNING(a_LogWarnings, "Cannot parse block data for piece %s in cubeset %s", a_PieceName.c_str(), a_FileName.c_str());
return nullptr;
}
// Call table.concat() on the BlockDefinitions:
AString BlockDefStr;
if (!a_LuaState.Call(TableConcat, BlockDefinitions, "\n", cLuaState::Return, BlockDefStr))
{
CONDWARNING(a_LogWarnings, "Cannot concat block definitions for piece %s in cubeset %s", a_PieceName.c_str(), a_FileName.c_str());
return nullptr;
}
// Call table.concat() on the BlockData:
AString BlockDataStr;
if (!a_LuaState.Call(TableConcat, BlockData, "", cLuaState::Return, BlockDataStr))
{
CONDWARNING(a_LogWarnings, "Cannot concat block data for piece %s in cubeset %s", a_PieceName.c_str(), a_FileName.c_str());
return nullptr;
}
// Read the size:
int SizeX = 0, SizeY = 0, SizeZ = 0;
if (
!a_LuaState.GetNamedValue("Size.x", SizeX) ||
!a_LuaState.GetNamedValue("Size.y", SizeY) ||
!a_LuaState.GetNamedValue("Size.z", SizeZ)
)
{
CONDWARNING(a_LogWarnings, "Cannot load piece %s from file %s, its size information is missing", a_PieceName.c_str(), a_FileName.c_str());
return nullptr;
}
// Check that the size matches the data length:
if (static_cast<size_t>(SizeX * SizeY * SizeZ) != BlockDataStr.size())
{
CONDWARNING(a_LogWarnings, "Cannot create piece %s from file %s, its size (%d) doesn't match the blockdata length (%u)",
a_PieceName.c_str(), a_FileName.c_str(),
SizeX * SizeY * SizeZ, static_cast<unsigned>(BlockDataStr.size())
);
return nullptr;
}
return cpp14::make_unique<cPrefab>(BlockDefStr, BlockDataStr, SizeX, SizeY, SizeZ);
}
示例15: HandleWebadminRequest
void cWebAdmin::HandleWebadminRequest(cHTTPConnection & a_Connection, cHTTPRequest & a_Request)
{
if (!a_Request.HasAuth())
{
a_Connection.SendNeedAuth("MCServer WebAdmin");
return;
}
// Check auth:
AString UserPassword = m_IniFile.GetValue("User:" + a_Request.GetAuthUsername(), "Password", "");
if ((UserPassword == "") || (a_Request.GetAuthPassword() != UserPassword))
{
a_Connection.SendNeedAuth("MCServer WebAdmin - bad username or password");
return;
}
// Check if the contents should be wrapped in the template:
AString URL = a_Request.GetBareURL();
ASSERT(URL.length() > 0);
bool ShouldWrapInTemplate = ((URL.length() > 1) && (URL[1] != '~'));
// Retrieve the request data:
cWebadminRequestData * Data = (cWebadminRequestData *)(a_Request.GetUserData());
if (Data == NULL)
{
a_Connection.SendStatusAndReason(500, "Bad UserData");
return;
}
// Wrap it all up for the Lua call:
AString Template;
HTTPTemplateRequest TemplateRequest;
TemplateRequest.Request.Username = a_Request.GetAuthUsername();
TemplateRequest.Request.Method = a_Request.GetMethod();
TemplateRequest.Request.Path = URL.substr(1);
if (Data->m_Form.Finish())
{
for (cHTTPFormParser::const_iterator itr = Data->m_Form.begin(), end = Data->m_Form.end(); itr != end; ++itr)
{
HTTPFormData HTTPfd;
HTTPfd.Value = itr->second;
HTTPfd.Type = "";
HTTPfd.Name = itr->first;
TemplateRequest.Request.FormData[itr->first] = HTTPfd;
TemplateRequest.Request.PostParams[itr->first] = itr->second;
} // for itr - Data->m_Form[]
// Parse the URL into individual params:
size_t idxQM = a_Request.GetURL().find('?');
if (idxQM != AString::npos)
{
cHTTPFormParser URLParams(cHTTPFormParser::fpkURL, a_Request.GetURL().c_str() + idxQM + 1, a_Request.GetURL().length() - idxQM - 1, *Data);
URLParams.Finish();
for (cHTTPFormParser::const_iterator itr = URLParams.begin(), end = URLParams.end(); itr != end; ++itr)
{
TemplateRequest.Request.Params[itr->first] = itr->second;
} // for itr - URLParams[]
}
}
// Try to get the template from the Lua template script
if (ShouldWrapInTemplate)
{
if (m_TemplateScript.Call("ShowPage", this, &TemplateRequest, cLuaState::Return, Template))
{
cHTTPResponse Resp;
Resp.SetContentType("text/html");
a_Connection.Send(Resp);
a_Connection.Send(Template.c_str(), Template.length());
return;
}
a_Connection.SendStatusAndReason(500, "m_TemplateScript failed");
return;
}
AString BaseURL = GetBaseURL(URL);
AString Menu;
Template = "{CONTENT}";
AString FoundPlugin;
for (PluginList::iterator itr = m_Plugins.begin(); itr != m_Plugins.end(); ++itr)
{
cWebPlugin * WebPlugin = *itr;
std::list< std::pair<AString, AString> > NameList = WebPlugin->GetTabNames();
for (std::list< std::pair<AString, AString> >::iterator Names = NameList.begin(); Names != NameList.end(); ++Names)
{
Menu += "<li><a href='" + BaseURL + WebPlugin->GetWebTitle().c_str() + "/" + (*Names).second + "'>" + (*Names).first + "</a></li>";
}
}
sWebAdminPage Page = GetPage(TemplateRequest.Request);
AString Content = Page.Content;
FoundPlugin = Page.PluginName;
if (!Page.TabName.empty())
{
FoundPlugin += " - " + Page.TabName;
}
if (FoundPlugin.empty()) // Default page
//.........这里部分代码省略.........