本文整理汇总了C++中common::String::end方法的典型用法代码示例。如果您正苦于以下问题:C++ String::end方法的具体用法?C++ String::end怎么用?C++ String::end使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common::String
的用法示例。
在下文中一共展示了String::end方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: genLocalizedFontFilename
Common::String FontManager::genLocalizedFontFilename(const Common::String &filename) const {
#ifndef USE_TRANSLATION
return filename;
#else
// We will transform the font filename in the following way:
// name.bdf
// will become:
// name-charset.bdf
// Note that name should not contain any dot here!
// In the first step we look for the dot. In case there is none we will
// return the normal filename.
Common::String::const_iterator dot = Common::find(filename.begin(), filename.end(), '.');
if (dot == filename.end())
return filename;
// Put the translated font filename string back together.
Common::String result(filename.begin(), dot);
result += '-';
result += TransMan.getCurrentCharset();
result += dot;
return result;
#endif
}
示例2: listSavegames
void listSavegames(Common::Array<SavegameDesc> &saves) {
Common::SaveFileManager *saveFileMan = g_engine->getSaveFileManager();
// Load all saves
Common::StringList saveNames = saveFileMan->listSavefiles(((SciEngine *)g_engine)->getSavegamePattern());
for (Common::StringList::const_iterator iter = saveNames.begin(); iter != saveNames.end(); ++iter) {
Common::String filename = *iter;
Common::SeekableReadStream *in;
if ((in = saveFileMan->openForLoading(filename))) {
SavegameMetadata meta;
if (!get_savegame_metadata(in, &meta)) {
// invalid
delete in;
continue;
}
delete in;
SavegameDesc desc;
desc.id = strtol(filename.end() - 3, NULL, 10);
desc.date = meta.savegame_date;
desc.time = meta.savegame_time;
debug(3, "Savegame in file %s ok, id %d", filename.c_str(), desc.id);
saves.push_back(desc);
}
}
// Sort the list by creation date of the saves
qsort(saves.begin(), saves.size(), sizeof(SavegameDesc), _savegame_index_struct_compare);
}
示例3: printString
void Display::printString(const Common::String &str) {
Common::String::const_iterator c;
for (c = str.begin(); c != str.end(); ++c) {
byte b = *c;
if (*c == APPLECHAR('\r'))
_cursorPos = (_cursorPos / TEXT_WIDTH + 1) * TEXT_WIDTH;
else if (b < 0x80 || b >= 0xa0) {
setCharAtCursor(b);
++_cursorPos;
}
if (_cursorPos == TEXT_BUF_SIZE)
scrollUp();
}
updateTextScreen();
}
示例4: convertToASCII
/* Converts CP895 string to 7bit ASCII, so we can show it in the console. */
static Common::String convertToASCII(const Common::String &str) {
static const char conversionTable[] = {
'C', 'u', 'e', 'd', 'a', 'D', 'T', 'c', 'e', 'E', 'L', 'I', 'l', 'l', 'A', 'A', /* 0x80-0x8F */
'E', 'z', 'Z', 'o', 'o', 'O', 'u', 'U', 'y', 'O', 'U', 'S', 'L', 'Y', 'R', 't', /* 0x90-0x9F */
'a', 'i', 'o', 'u', 'n', 'N', 'U', 'O', 's', 'r', 'r', 'R' /* 0xA0-0xAB */
};
Common::String ret = str;
for (Common::String::iterator it = ret.begin(); it != ret.end(); ++it) {
const byte cp895Byte = reinterpret_cast<const byte &>(*it);
if (cp895Byte >= 0x80 && cp895Byte <= 0xAB) {
*it = conversionTable[cp895Byte - 0x80];
} else if (cp895Byte == 0xE1) { // ß
*it = 's';
}
}
return ret;
}
示例5: StateScript
Common::Error GagEngine::StateScript()
{
Common::Error status(Common::kNoError);
Common::File file;
if(file.open(_script, *_archive))
{
// simple script parsing: skim through, find section and execute commands
ParserState parse_state(PS_SECTION_SEARCH);
Common::String buffer;
Common::String command_name;
bool done(false);
while(!file.eos())
{
// add space for multiline command support
Common::String line = file.readLine() + ' ';
if(file.err())
{
status = Common::Error(Common::kReadingFailed, _script + ", readLine()");
break;
}
bool skip_line(false);
for(Common::String::const_iterator it = line.begin(); it != line.end(); ++it)
{
switch(parse_state)
{
case PS_SECTION_SEARCH:
// section
if(*it == '[')
{
buffer.clear();
parse_state = PS_SECTION_NAME;
}
break;
case PS_SECTION_NAME:
// section end
if(*it == ']')
{
#ifdef DEBUG_SKIM_SCRIPT
parse_state = PS_SECTION_BODY;
#else
if(buffer == _section)
parse_state = PS_SECTION_BODY;
else if(buffer == _END_SECTION)
{
status = Common::Error(Common::kUnknownError, "[" + _section + "] script section not found");
skip_line = true;
done = true;
}
else
parse_state = PS_SECTION_SEARCH;
#endif
}
else
buffer += *it;
break;
case PS_SECTION_BODY:
// section
if(*it == '[')
{
#ifdef DEBUG_SKIM_SCRIPT
buffer.clear();
parse_state = PS_SECTION_NAME;
#else
skip_line = true;
done = true;
#endif
}
// comment
else if(*it == '*')
{
skip_line = true;
}
//NOTE: invalid syntax
else if(*it == '-' || *it == '/' || (*it >= 'A' && *it <= 'Z'))
{
#ifndef DEBUG_SKIM_SCRIPT
warning("invalid script syntax [file: %s, section: %s, line: \"%s\"], skipped", _script.c_str(), _section.c_str(), line.c_str());
#endif
skip_line = true;
}
// command name
else if((*it >= 'a' && *it <= 'z'))
{
buffer.clear();
buffer += *it;
parse_state = PS_COMMAND_NAME;
}
break;
case PS_COMMAND_NAME:
// command value
if(*it == '=')
{
//.........这里部分代码省略.........
示例6: wordWrapText
int Font::wordWrapText(const Common::String &str, int maxWidth, Common::Array<Common::String> &lines) const {
WordWrapper wrapper(lines);
Common::String line;
Common::String tmpStr;
int lineWidth = 0;
int tmpWidth = 0;
// The rough idea behind this algorithm is as follows:
// We accumulate characters into the string tmpStr. Whenever a full word
// has been gathered together this way, we 'commit' it to the line buffer
// 'line', i.e. we add tmpStr to the end of line, then clear it. Before
// we do that, we check whether it would cause 'line' to exceed maxWidth;
// in that case, we first add line to lines, then reset it.
//
// If a newline character is read, then we also add line to lines and clear it.
//
// Special care has to be taken to account for 'words' that exceed the width
// of a line. If we encounter such a word, we have to wrap it over multiple
// lines.
uint last = 0;
for (Common::String::const_iterator x = str.begin(); x != str.end(); ++x) {
const byte c = *x;
const int w = getCharWidth(c) + getKerningOffset(last, c);
last = c;
const bool wouldExceedWidth = (lineWidth + tmpWidth + w > maxWidth);
// If this char is a whitespace, then it represents a potential
// 'wrap point' where wrapping could take place. Everything that
// came before it can now safely be added to the line, as we know
// that it will not have to be wrapped.
if (Common::isSpace(c)) {
line += tmpStr;
lineWidth += tmpWidth;
tmpStr.clear();
tmpWidth = 0;
// If we encounter a line break (\n), or if the new space would
// cause the line to overflow: start a new line
if (c == '\n' || wouldExceedWidth) {
wrapper.add(line, lineWidth);
continue;
}
}
// If the max line width would be exceeded by adding this char,
// insert a line break.
if (wouldExceedWidth) {
// Commit what we have so far, *if* we have anything.
// If line is empty, then we are looking at a word
// which exceeds the maximum line width.
if (lineWidth > 0) {
wrapper.add(line, lineWidth);
// Trim left side
while (tmpStr.size() && Common::isSpace(tmpStr[0])) {
tmpStr.deleteChar(0);
// This is not very fast, but it is the simplest way to
// assure we do not mess something up because of kerning.
tmpWidth = getStringWidth(tmpStr);
}
} else {
wrapper.add(tmpStr, tmpWidth);
}
}
tmpWidth += w;
tmpStr += c;
}
// If some text is left over, add it as the final line
line += tmpStr;
lineWidth += tmpWidth;
if (lineWidth > 0) {
wrapper.add(line, lineWidth);
}
return wrapper.actualMaxLineWidth;
}