本文整理汇总了C++中StringRange::StripUTF8BOM方法的典型用法代码示例。如果您正苦于以下问题:C++ StringRange::StripUTF8BOM方法的具体用法?C++ StringRange::StripUTF8BOM怎么用?C++ StringRange::StripUTF8BOM使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringRange
的用法示例。
在下文中一共展示了StringRange::StripUTF8BOM方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Read
void IniConfig::Read(const FileSystem::FileData &data)
{
StringRange buffer = data.AsStringRange();
buffer = buffer.StripUTF8BOM();
std::string section_name;
MapType *section_map = 0;
while (!buffer.Empty()) {
StringRange line = buffer.ReadLine().StripSpace();
// if the line is a comment, skip it
if (line.Empty() || (line[0] == '#')) continue;
// check for a section header
if ((line.Size() >= 2) && (line[0] == '[') && (line.end[-1] == ']')) {
++line.begin;
--line.end;
section_name = line.ToString();
section_map = 0;
continue;
}
const char *kend = line.FindChar('=');
// if there's no '=' sign, skip the line
if (kend == line.end) {
Output("WARNING: ignoring invalid line in config file:\n '%.*s'\n", int(line.Size()), line.begin);
continue;
}
StringRange key(line.begin, kend);
StringRange value(kend + 1, line.end);
// strip whitespace
key.end = key.RFindNonSpace();
value = value.StripSpace();
if (!section_map)
section_map = &m_map[section_name];
(*section_map)[key.ToString()] = value.ToString();
}
}
示例2: strCode
Shader(GLenum type, const std::string &filename, const std::string &defines)
{
RefCountedPtr<FileSystem::FileData> filecode = FileSystem::gameDataFiles.ReadFile(filename);
if (!filecode.Valid())
Error("Could not load %s", filename.c_str());
std::string strCode(filecode->AsStringRange().ToString());
size_t found = strCode.find("#include");
while (found != std::string::npos)
{
// find the name of the file to include
const size_t begFilename = strCode.find_first_of("\"", found + 8) + 1;
const size_t endFilename = strCode.find_first_of("\"", begFilename + 1);
const std::string incFilename = strCode.substr(begFilename, endFilename - begFilename);
// check we haven't it already included it (avoids circular dependencies)
const std::set<std::string>::const_iterator foundIt = previousIncludes.find(incFilename);
if (foundIt != previousIncludes.end()) {
Error("Circular, or multiple, include of %s\n", incFilename.c_str());
}
else {
previousIncludes.insert(incFilename);
}
// build path for include
const std::string incPathBuffer = stringf("shaders/opengl/%0", incFilename);
// read included file
RefCountedPtr<FileSystem::FileData> incCode = FileSystem::gameDataFiles.ReadFile(incPathBuffer);
assert(incCode.Valid());
if (incCode.Valid()) {
// replace the #include and filename with the included files text
strCode.replace(found, (endFilename + 1) - found, incCode->GetData(), incCode->GetSize());
found = strCode.find("#include");
}
else {
Error("Could not load %s", incPathBuffer.c_str());
}
}
// Store the modified text with the included files (if any)
const StringRange code(strCode.c_str(), strCode.size());
// Build the final shader text to be compiled
AppendSource(s_glslVersion);
AppendSource(defines.c_str());
if (type == GL_VERTEX_SHADER) {
AppendSource("#define VERTEX_SHADER\n");
} else {
AppendSource("#define FRAGMENT_SHADER\n");
}
AppendSource(code.StripUTF8BOM());
#if 0
static bool s_bDumpShaderSource = true;
if (s_bDumpShaderSource) {
const char SHADER_OUT_DIR_NAME[] = "shaders";
const char SHADER_OGL_OUT_DIR_NAME[] = "shaders/opengl";
FileSystem::userFiles.MakeDirectory(SHADER_OUT_DIR_NAME);
FileSystem::userFiles.MakeDirectory(SHADER_OGL_OUT_DIR_NAME);
const std::string outFilename(FileSystem::GetUserDir() + "/" + filename);
FILE *tmp = fopen(outFilename.c_str(), "wb");
if(tmp) {
Output("%s", filename);
for( Uint32 i=0; i<blocks.size(); i++ ) {
const char *block = blocks[i];
const GLint sizes = block_sizes[i];
if(block && sizes>0) {
fprintf(tmp, "%.*s", sizes, block);
}
}
fclose(tmp);
} else {
Output("Could not open file %s", outFilename.c_str());
}
}
#endif
shader = glCreateShader(type);
if(glIsShader(shader)!=GL_TRUE)
throw ShaderException();
Compile(shader);
// CheckGLSL may use OS::Warning instead of Error so the game may still (attempt to) run
if (!check_glsl_errors(filename.c_str(), shader))
throw ShaderException();
};