本文整理汇总了C++中common::String::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ String::clear方法的具体用法?C++ String::clear怎么用?C++ String::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common::String
的用法示例。
在下文中一共展示了String::clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getTextFromAnyVar
Common::String getTextFromAnyVar(const Variable &from) {
switch (from.varType) {
case SVT_STRING:
return from.varData.theString;
case SVT_FASTARRAY: {
Common::String builder = "FAST:";
Common::String builder2 = "";
Common::String grabText = "";
for (int i = 0; i < from.varData.fastArray->size; i++) {
builder2 = builder + " ";
grabText = getTextFromAnyVar(from.varData.fastArray->fastVariables[i]);
builder.clear();
builder = builder2 + grabText;
}
return builder;
}
case SVT_STACK: {
Common::String builder = "ARRAY:";
Common::String builder2 = "";
Common::String grabText = "";
VariableStack *stacky = from.varData.theStack->first;
while (stacky) {
builder2 = builder + " ";
grabText = getTextFromAnyVar(stacky->thisVar);
builder.clear();
builder = builder2 + grabText;
stacky = stacky->next;
}
return builder;
}
case SVT_INT: {
Common::String buff = Common::String::format("%i", from.varData.intValue);
return buff;
}
case SVT_FILE: {
return resourceNameFromNum(from.varData.intValue);
}
case SVT_OBJTYPE: {
ObjectType *thisType = g_sludge->_objMan->findObjectType(from.varData.intValue);
if (thisType)
return thisType->screenName;
break;
}
default:
break;
}
return typeName[from.varType];
}
示例2: addLine
void AboutDialog::addLine(const char *str) {
if (*str == 0) {
_lines.push_back("");
} else {
Common::String format(str, 2);
str += 2;
static Common::String asciiStr;
if (format[0] == 'A') {
bool useAscii = false;
#ifdef USE_TRANSLATION
// We could use TransMan.getCurrentCharset() but rather than compare strings
// it is easier to use TransMan.getCharsetMapping() (non null in case of non
// ISO-8859-1 mapping)
useAscii = (TransMan.getCharsetMapping() != NULL);
#endif
if (useAscii)
asciiStr = str;
return;
}
StringArray wrappedLines;
if (!asciiStr.empty()) {
g_gui.getFont().wordWrapText(asciiStr, _w - 2 * _xOff, wrappedLines);
asciiStr.clear();
} else
g_gui.getFont().wordWrapText(str, _w - 2 * _xOff, wrappedLines);
for (StringArray::const_iterator i = wrappedLines.begin(); i != wrappedLines.end(); ++i) {
_lines.push_back(format + *i);
}
}
}
示例3: add
void add(Common::String &line, int &w) {
if (actualMaxLineWidth < w)
actualMaxLineWidth = w;
lines.push_back(line);
line.clear();
w = 0;
}
示例4: askForSaveGameDescription
bool SystemUI::askForSaveGameDescription(int16 slotId, Common::String &newDescription) {
// Let user enter new description
bool previousEditState = _text->inputGetEditStatus();
byte previousEditCursor = _text->inputGetCursorChar();
_text->drawMessageBox(_textSaveGameEnterDescription, 0, 31, true);
_text->inputEditOn();
_text->charPos_Push();
_text->charAttrib_Push();
_text->charPos_SetInsideWindow(3, 0);
_text->charAttrib_Set(15, 0);
_text->clearBlockInsideWindow(3, 0, 31, 0); // input line is supposed to be black
_text->inputSetCursorChar('_');
// figure out the current description of the slot
_text->stringSet("");
for (uint16 slotNr = 0; slotNr < _savedGameArray.size(); slotNr++) {
if (_savedGameArray[slotNr].slotId == slotId) {
// found slotId
if (_savedGameArray[slotNr].isValid) {
// and also valid, so use its description
_text->stringSet(_savedGameArray[slotNr].description);
}
}
}
_vm->cycleInnerLoopActive(CYCLE_INNERLOOP_GETSTRING);
_text->stringEdit(30); // only allow up to 30 characters
_text->charAttrib_Pop();
_text->charPos_Pop();
_text->inputSetCursorChar(previousEditCursor);
if (!previousEditState) {
_text->inputEditOff();
}
_text->closeWindow();
if (!_text->stringWasEntered()) {
// User cancelled? exit now
return false;
}
// Now verify that the user really wants to do this
if (!askForSavedGameVerification(_textSaveGameVerify, _textSaveGameVerifyButton1, _textSaveGameVerifyButton2, (char *)_text->_inputString, slotId)) {
return false;
}
newDescription.clear();
newDescription += (char *)_text->_inputString;
return true;
}
示例5: selectSaveFile
int SaveLoad::selectSaveFile(Common::String &selectedName, bool saveMode, const Common::String &caption, const Common::String &button) {
GUI::SaveLoadChooser slc(caption, button, saveMode);
selectedName.clear();
int idx = slc.runModalWithCurrentTarget();
if (idx >= 0) {
selectedName = slc.getResultString();
}
return idx;
}
示例6: cmd_saveOriginal
bool Debugger_EoB::cmd_saveOriginal(int argc, const char **argv) {
if (!_vm->_runFlag) {
DebugPrintf("This command doesn't work during intro or outro sequences,\nfrom the main menu or from the character generation.\n");
return true;
}
Common::String dir = ConfMan.get("savepath");
if (dir == "None")
dir.clear();
Common::FSNode nd(dir);
if (!nd.isDirectory())
return false;
if (_vm->game() == GI_EOB1) {
if (argc == 1) {
if (_vm->saveAsOriginalSaveFile()) {
Common::FSNode nf = nd.getChild(Common::String::format("EOBDATA.SAV"));
if (nf.isReadable())
DebugPrintf("Saved to file: %s\n\n", nf.getPath().c_str());
else
DebugPrintf("Failure.\n");
} else {
DebugPrintf("Failure.\n");
}
} else {
DebugPrintf("Syntax: save_original\n (Saves game in original file format to a file which can be used with the orginal game executable.)\n\n");
}
return true;
} else if (argc == 2) {
int slot = atoi(argv[1]);
if (slot < 0 || slot > 5) {
DebugPrintf("Slot must be between (including) 0 and 5.\n");
} else if (_vm->saveAsOriginalSaveFile(slot)) {
Common::FSNode nf = nd.getChild(Common::String::format("EOBDATA%d.SAV", slot));
if (nf.isReadable())
DebugPrintf("Saved to file: %s\n\n", nf.getPath().c_str());
else
DebugPrintf("Failure.\n");
} else {
DebugPrintf("Failure.\n");
}
return true;
}
DebugPrintf("Syntax: save_original <slot>\n (Saves game in original file format to a file which can be used with the orginal game executable.\n A save slot between 0 and 5 must be specified.)\n\n");
return true;
}
示例7: getLine
bool Font::getLine(Common::String &s, int maxWidth, Common::String &line, int &width) {
assert(maxWidth > 0);
width = 0;
const char *src = s.c_str();
char c;
while ((c = *src) != '\0') {
if (c == '\r') {
// End of line, so return calculated line
line = Common::String(s.c_str(), src);
s = Common::String(src + 1);
return false;
}
++src;
width += charWidth(c);
if (width < maxWidth)
continue;
// Reached maximum allowed size
// If this was the last character of the string, let it go
if (*src == '\0') {
line = Common::String(s.c_str(), src);
s.clear();
return true;
}
// Work backwards to find space at the start of the current word
// as a point to split the line on
while (src >= s.c_str() && *src != ' ') {
width -= charWidth(*src);
--src;
}
if (src < s.c_str())
error("Could not fit line");
// Split the line around the space
line = Common::String(s.c_str(), src);
s = Common::String(src + 1);
return false;
}
// Return entire string
line = s;
s = Common::String();
return true;
}
示例8:
void ResourceSerializer::syncAsString32(Common::String &string) {
if (isLoading()) {
string.clear();
uint32 length = _loadStream->readUint32LE();
for (uint i = 0; i < length; i++) {
char c = _loadStream->readByte();
string += c;
}
_bytesSynced += 4 + length;
} else {
_saveStream->writeUint32LE(string.size());
_saveStream->writeString(string);
_bytesSynced += 4 + string.size();
}
}
示例9: selectSaveFile
int SaveLoad::selectSaveFile(Common::String &selectedName, bool saveMode, const Common::String &caption, const Common::String &button) {
GUI::SaveLoadChooser slc(caption, button);
slc.setSaveMode(saveMode);
selectedName.clear();
Common::String gameId = ConfMan.get("gameid");
const EnginePlugin *plugin = 0;
EngineMan.findGame(gameId, &plugin);
int idx = slc.runModalWithPluginAndTarget(plugin, ConfMan.getActiveDomainName());
if (idx >= 0) {
selectedName = slc.getResultString();
slc.close();
}
return idx;
}
示例10: result
Common::Archive *ResLoaderInsMalcolm::load(Common::ArchiveMemberPtr memberFile, Common::SeekableReadStream &stream) const {
Common::List<Common::String> filenames;
Common::ScopedPtr<PlainArchive> result(new PlainArchive(memberFile));
if (!result)
return 0;
// thanks to eriktorbjorn for this code (a bit modified though)
stream.seek(3, SEEK_SET);
// first file is the index table
uint32 size = stream.readUint32LE();
Common::String temp;
for (uint32 i = 0; i < size; ++i) {
byte c = stream.readByte();
if (c == '\\') {
temp.clear();
} else if (c == 0x0D) {
// line endings are CRLF
c = stream.readByte();
assert(c == 0x0A);
++i;
filenames.push_back(temp);
} else {
temp += (char)c;
}
}
stream.seek(3, SEEK_SET);
for (Common::List<Common::String>::iterator file = filenames.begin(); file != filenames.end(); ++file) {
const uint32 fileSize = stream.readUint32LE();
const uint32 fileOffset = stream.pos();
result->addFileEntry(*file, PlainArchive::Entry(fileOffset, fileSize));
stream.seek(fileSize, SEEK_CUR);
}
return result.release();
}
示例11: askForCommand
bool SystemUI::askForCommand(Common::String &commandText) {
// Let user enter the command (this was originally only available for Hercules rendering, we allow it everywhere)
bool previousEditState = _text->inputGetEditStatus();
byte previousEditCursor = _text->inputGetCursorChar();
_text->drawMessageBox(_textEnterCommand, 0, 36, true);
_text->inputEditOn();
_text->charPos_Push();
_text->charAttrib_Push();
_text->charPos_SetInsideWindow(2, 0);
_text->charAttrib_Set(15, 0);
_text->clearBlockInsideWindow(2, 0, 36, 0); // input line is supposed to be black
_text->inputSetCursorChar('_');
_text->stringSet(commandText.c_str()); // Set current command text (may be a command recall)
_vm->cycleInnerLoopActive(CYCLE_INNERLOOP_GETSTRING);
_text->stringEdit(35); // only allow up to 35 characters
_text->charAttrib_Pop();
_text->charPos_Pop();
_text->inputSetCursorChar(previousEditCursor);
if (!previousEditState) {
_text->inputEditOff();
}
_text->closeWindow();
if (!_text->stringWasEntered()) {
// User cancelled? exit now
return false;
}
commandText.clear();
commandText += (char *)_text->_inputString;
return true;
}
示例12: printData
void AnimVideo::printData() {
Anim::printData();
debug("smackerFile: %s", _smackerFile.c_str());
debug("size: x %d, y %d", _width, _height);
Common::String description;
for (uint32 i = 0; i < _positions.size(); i++) {
description += Common::String::format("(x %d, y %d) ", _positions[i].x, _positions[i].y);
}
debug("positions: %s", description.c_str());
description.clear();
for (uint32 i = 0; i < _sizes.size(); i++) {
description += Common::String::format("(l %d, t %d, r %d, b %d) ",
_sizes[i].left, _sizes[i].top, _sizes[i].right, _sizes[i].bottom);
}
debug("sizes: %s", description.c_str());
debug("frameRateOverride): %d", _frameRateOverride);
debug("preload: %d", _preload);
debug("loop: %d", _loop);
}
示例13: readSelectorValue
void GfxControls16::kernelTexteditChange(reg_t controlObject, reg_t eventObject) {
uint16 cursorPos = readSelectorValue(_segMan, controlObject, SELECTOR(cursor));
uint16 maxChars = readSelectorValue(_segMan, controlObject, SELECTOR(max));
reg_t textReference = readSelector(_segMan, controlObject, SELECTOR(text));
Common::String text;
uint16 textSize, eventType, eventKey = 0, modifiers = 0;
bool textChanged = false;
bool textAddChar = false;
Common::Rect rect;
if (textReference.isNull())
error("kEditControl called on object that doesnt have a text reference");
text = _segMan->getString(textReference);
uint16 oldCursorPos = cursorPos;
if (!eventObject.isNull()) {
textSize = text.size();
eventType = readSelectorValue(_segMan, eventObject, SELECTOR(type));
switch (eventType) {
case SCI_EVENT_MOUSE_PRESS:
// TODO: Implement mouse support for cursor change
break;
case SCI_EVENT_KEYBOARD:
eventKey = readSelectorValue(_segMan, eventObject, SELECTOR(message));
modifiers = readSelectorValue(_segMan, eventObject, SELECTOR(modifiers));
switch (eventKey) {
case SCI_KEY_BACKSPACE:
if (cursorPos > 0) {
cursorPos--; text.deleteChar(cursorPos);
textChanged = true;
}
break;
case SCI_KEY_DELETE:
if (cursorPos < textSize) {
text.deleteChar(cursorPos);
textChanged = true;
}
break;
case SCI_KEY_HOME: // HOME
cursorPos = 0; textChanged = true;
break;
case SCI_KEY_END: // END
cursorPos = textSize; textChanged = true;
break;
case SCI_KEY_LEFT: // LEFT
if (cursorPos > 0) {
cursorPos--; textChanged = true;
}
break;
case SCI_KEY_RIGHT: // RIGHT
if (cursorPos + 1 <= textSize) {
cursorPos++; textChanged = true;
}
break;
case 3: // returned in SCI1 late and newer when Control - C is pressed
if (modifiers & SCI_KEYMOD_CTRL) {
// Control-C erases the whole line
cursorPos = 0; text.clear();
textChanged = true;
}
break;
default:
if ((modifiers & SCI_KEYMOD_CTRL) && eventKey == 99) {
// Control-C in earlier SCI games (SCI0 - SCI1 middle)
// Control-C erases the whole line
cursorPos = 0; text.clear();
textChanged = true;
} else if (eventKey > 31 && eventKey < 256 && textSize < maxChars) {
// insert pressed character
textAddChar = true;
textChanged = true;
}
break;
}
break;
}
}
if (g_sci->getVocabulary() && !textChanged && oldCursorPos != cursorPos) {
assert(!textAddChar);
textChanged = g_sci->getVocabulary()->checkAltInput(text, cursorPos);
}
if (textChanged) {
GuiResourceId oldFontId = _text16->GetFontId();
GuiResourceId fontId = readSelectorValue(_segMan, controlObject, SELECTOR(font));
rect = g_sci->_gfxCompare->getNSRect(controlObject);
_text16->SetFont(fontId);
if (textAddChar) {
const char *textPtr = text.c_str();
// We check if we are really able to add the new char
uint16 textWidth = 0;
while (*textPtr)
textWidth += _text16->_font->getCharWidth((byte)*textPtr++);
textWidth += _text16->_font->getCharWidth(eventKey);
//.........这里部分代码省略.........
示例14: SELECTOR
void GfxControls32::kernelTexteditChange(reg_t controlObject) {
SciEvent curEvent;
uint16 maxChars = 40; //readSelectorValue(_segMan, controlObject, SELECTOR(max)); // TODO
reg_t textReference = readSelector(_segMan, controlObject, SELECTOR(text));
GfxFont *font = _cache->getFont(readSelectorValue(_segMan, controlObject, SELECTOR(font)));
Common::String text;
uint16 textSize;
bool textChanged = false;
bool textAddChar = false;
Common::Rect rect;
if (textReference.isNull())
error("kEditControl called on object that doesn't have a text reference");
text = _segMan->getString(textReference);
// TODO: Finish this
warning("kEditText ('%s')", text.c_str());
return;
uint16 cursorPos = 0;
//uint16 oldCursorPos = cursorPos;
bool captureEvents = true;
EventManager* eventMan = g_sci->getEventManager();
while (captureEvents) {
curEvent = g_sci->getEventManager()->getSciEvent(SCI_EVENT_KEYBOARD | SCI_EVENT_PEEK);
if (curEvent.type == SCI_EVENT_NONE) {
eventMan->getSciEvent(SCI_EVENT_KEYBOARD); // consume the event
} else {
textSize = text.size();
switch (curEvent.type) {
case SCI_EVENT_MOUSE_PRESS:
// TODO: Implement mouse support for cursor change
break;
case SCI_EVENT_KEYBOARD:
switch (curEvent.character) {
case SCI_KEY_BACKSPACE:
if (cursorPos > 0) {
cursorPos--; text.deleteChar(cursorPos);
textChanged = true;
}
eventMan->getSciEvent(SCI_EVENT_KEYBOARD); // consume the event
break;
case SCI_KEY_DELETE:
if (cursorPos < textSize) {
text.deleteChar(cursorPos);
textChanged = true;
}
eventMan->getSciEvent(SCI_EVENT_KEYBOARD); // consume the event
break;
case SCI_KEY_HOME: // HOME
cursorPos = 0; textChanged = true;
eventMan->getSciEvent(SCI_EVENT_KEYBOARD); // consume the event
break;
case SCI_KEY_END: // END
cursorPos = textSize; textChanged = true;
eventMan->getSciEvent(SCI_EVENT_KEYBOARD); // consume the event
break;
case SCI_KEY_LEFT: // LEFT
if (cursorPos > 0) {
cursorPos--; textChanged = true;
}
eventMan->getSciEvent(SCI_EVENT_KEYBOARD); // consume the event
break;
case SCI_KEY_RIGHT: // RIGHT
if (cursorPos + 1 <= textSize) {
cursorPos++; textChanged = true;
}
eventMan->getSciEvent(SCI_EVENT_KEYBOARD); // consume the event
break;
case 3: // returned in SCI1 late and newer when Control - C is pressed
if (curEvent.modifiers & SCI_KEYMOD_CTRL) {
// Control-C erases the whole line
cursorPos = 0; text.clear();
textChanged = true;
}
eventMan->getSciEvent(SCI_EVENT_KEYBOARD); // consume the event
break;
case SCI_KEY_UP:
case SCI_KEY_DOWN:
case SCI_KEY_ENTER:
case SCI_KEY_ESC:
case SCI_KEY_TAB:
case SCI_KEY_SHIFT_TAB:
captureEvents = false;
break;
default:
if ((curEvent.modifiers & SCI_KEYMOD_CTRL) && curEvent.character == 'c') {
// Control-C in earlier SCI games (SCI0 - SCI1 middle)
// Control-C erases the whole line
cursorPos = 0; text.clear();
textChanged = true;
} else if (curEvent.character > 31 && curEvent.character < 256 && textSize < maxChars) {
// insert pressed character
textAddChar = true;
textChanged = true;
}
eventMan->getSciEvent(SCI_EVENT_KEYBOARD); // consume the event
//.........这里部分代码省略.........
示例15: saveDir
POSIXSaveFileManager::POSIXSaveFileManager() {
// Register default savepath.
#if defined(SAMSUNGTV)
ConfMan.registerDefault("savepath", "/mtd_wiselink/scummvm savegames");
#else
Common::String savePath;
#if defined(MACOSX)
const char *home = getenv("HOME");
if (home && *home && strlen(home) < MAXPATHLEN) {
savePath = home;
savePath += "/Documents/ScummVM Savegames";
ConfMan.registerDefault("savepath", savePath);
}
#else
const char *envVar;
// Previously we placed our default savepath in HOME. If the directory
// still exists, we will use it for backwards compatability.
envVar = getenv("HOME");
if (envVar && *envVar) {
savePath = envVar;
savePath += "/.scummvm";
struct stat sb;
if (stat(savePath.c_str(), &sb) != 0 || !S_ISDIR(sb.st_mode)) {
savePath.clear();
}
}
if (savePath.empty()) {
Common::String prefix;
// On POSIX systems we follow the XDG Base Directory Specification for
// where to store files. The version we based our code upon can be found
// over here: http://standards.freedesktop.org/basedir-spec/basedir-spec-0.8.html
envVar = getenv("XDG_DATA_HOME");
if (!envVar || !*envVar) {
envVar = getenv("HOME");
if (envVar && *envVar) {
prefix = envVar;
savePath = ".local/share/";
}
} else {
prefix = envVar;
}
// Our default save path is '$XDG_DATA_HOME/scummvm/saves'
savePath += "scummvm/saves";
if (!Posix::assureDirectoryExists(savePath, prefix.c_str())) {
savePath.clear();
} else {
savePath = prefix + '/' + savePath;
}
}
if (!savePath.empty() && savePath.size() < MAXPATHLEN) {
ConfMan.registerDefault("savepath", savePath);
}
#endif
// The user can override the savepath with the SCUMMVM_SAVEPATH
// environment variable. This is weaker than a --savepath on the
// command line, but overrides the default savepath.
//
// To ensure that the command line option (if given) has precedence,
// we only set the value in the transient domain if it is not
// yet present there.
if (!ConfMan.hasKey("savepath", Common::ConfigManager::kTransientDomain)) {
const char *dir = getenv("SCUMMVM_SAVEPATH");
if (dir && *dir && strlen(dir) < MAXPATHLEN) {
Common::FSNode saveDir(dir);
if (!saveDir.exists()) {
warning("Ignoring non-existent SCUMMVM_SAVEPATH '%s'", dir);
} else if (!saveDir.isWritable()) {
warning("Ignoring non-writable SCUMMVM_SAVEPATH '%s'", dir);
} else {
ConfMan.set("savepath", dir, Common::ConfigManager::kTransientDomain);
}
}
}
#endif
}