本文整理汇总了C++中common::String::c_str方法的典型用法代码示例。如果您正苦于以下问题:C++ String::c_str方法的具体用法?C++ String::c_str怎么用?C++ String::c_str使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common::String
的用法示例。
在下文中一共展示了String::c_str方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: strtoul
/**
* Formats AGI string.
* This function turns a AGI string into a real string expanding values
* according to the AGI format specifiers.
* @param s string containing the format specifier
* @param n logic number
*/
char *AgiEngine::agiSprintf(const char *s) {
static char agiSprintf_buf[768];
Common::String p;
char z[16];
debugC(3, kDebugLevelText, "logic %d, '%s'", _game.lognum, s);
while (*s) {
switch (*s) {
case '%':
s++;
switch (*s++) {
int i;
case 'v':
i = strtoul(s, NULL, 10);
while (*s >= '0' && *s <= '9')
s++;
sprintf(z, "%015i", getvar(i));
i = 99;
if (*s == '|') {
s++;
i = strtoul(s, NULL, 10);
while (*s >= '0' && *s <= '9')
s++;
}
if (i == 99) {
// remove all leading 0
// don't remove the 3rd zero if 000
for (i = 0; z[i] == '0' && i < 14; i++)
;
} else {
i = 15 - i;
}
safeStrcat(p, z + i);
break;
case '0':
i = strtoul(s, NULL, 10) - 1;
safeStrcat(p, objectName(i));
break;
case 'g':
i = strtoul(s, NULL, 10) - 1;
safeStrcat(p, _game.logics[0].texts[i]);
break;
case 'w':
i = strtoul(s, NULL, 10) - 1;
safeStrcat(p, _game.egoWords[i].word);
break;
case 's':
i = strtoul(s, NULL, 10);
safeStrcat(p, agiSprintf(_game.strings[i]));
break;
case 'm':
i = strtoul(s, NULL, 10) - 1;
if (_game.logics[_game.lognum].numTexts > i)
safeStrcat(p, agiSprintf(_game.logics[_game.lognum].texts[i]));
break;
}
while (*s >= '0' && *s <= '9')
s++;
break;
case '\\':
s++;
// FALL THROUGH
default:
p += *s++;
break;
}
}
assert(p.size() < sizeof(agiSprintf_buf));
strcpy(agiSprintf_buf, p.c_str());
return agiSprintf_buf;
}
示例2: makeRequest
void OneDriveListDirectoryRequest::makeRequest(Common::String url) {
Networking::JsonCallback callback = new Common::Callback<OneDriveListDirectoryRequest, Networking::JsonResponse>(this, &OneDriveListDirectoryRequest::listedDirectoryCallback);
Networking::ErrorCallback failureCallback = new Common::Callback<OneDriveListDirectoryRequest, Networking::ErrorResponse>(this, &OneDriveListDirectoryRequest::listedDirectoryErrorCallback);
Networking::CurlJsonRequest *request = new OneDriveTokenRefresher(_storage, callback, failureCallback, url.c_str());
request->addHeader("Authorization: Bearer " + _storage->accessToken());
_workingRequest = ConnMan.addRequest(request);
}
示例3: call
void Lingo::call(Common::String &name, int nargs) {
bool drop = false;
Symbol *sym;
if (!g_lingo->_handlers.contains(name)) {
Symbol *s = g_lingo->lookupVar(name.c_str(), false);
if (s && s->type == OBJECT) {
debugC(3, kDebugLingoExec, "Dereferencing object reference: %s to %s", name.c_str(), s->u.s->c_str());
name = *s->u.s;
}
}
if (!g_lingo->_handlers.contains(name)) {
warning("Call to undefined handler '%s'. Dropping %d stack items", name.c_str(), nargs);
drop = true;
} else {
sym = g_lingo->_handlers[name];
if (sym->type == BLTIN && sym->nargs != -1 && sym->nargs != nargs && sym->maxArgs != nargs) {
if (sym->nargs == sym->maxArgs)
warning("Incorrect number of arguments to handler '%s', expecting %d. Dropping %d stack items", name.c_str(), sym->nargs, nargs);
else
warning("Incorrect number of arguments to handler '%s', expecting %d or %d. Dropping %d stack items", name.c_str(), sym->nargs, sym->maxArgs, nargs);
drop = true;
}
}
if (drop) {
for (int i = 0; i < nargs; i++)
g_lingo->pop();
// Push dummy value
g_lingo->pushVoid();
return;
}
if (sym->nargs != -1 && sym->nargs < nargs) {
warning("Incorrect number of arguments for function %s. Dropping extra %d", name.c_str(), nargs - sym->nargs);
for (int i = 0; i < nargs - sym->nargs; i++)
g_lingo->pop();
}
if (sym->type == BLTIN) {
if (sym->u.bltin == b_factory)
g_lingo->factoryCall(name, nargs);
else
(*sym->u.bltin)(nargs);
return;
}
for (int i = nargs; i < sym->nargs; i++) {
Datum d;
d.u.s = NULL;
d.type = VOID;
g_lingo->push(d);
}
debugC(5, kDebugLingoExec, "Pushing frame %d", g_lingo->_callstack.size() + 1);
CFrame *fp = new CFrame;
fp->sp = sym;
fp->retpc = g_lingo->_pc;
fp->retscript = g_lingo->_currentScript;
fp->localvars = g_lingo->_localvars;
// Create new set of local variables
g_lingo->_localvars = new SymbolHash;
g_lingo->_callstack.push_back(fp);
g_lingo->_currentScript = sym->u.defn;
g_lingo->execute(0);
g_lingo->_returning = false;
}
示例4: xbookclick
void OSpit::xbookclick(const ArgumentArray &args) {
// Let's hook onto our video
RivenVideo *video = _vm->_video->getSlot(args[0]);
// Convert from the standard QuickTime base time to milliseconds
// The values are in terms of 1/600 of a second.
// Have I said how much I just *love* QuickTime? </sarcasm>
uint32 startTime = args[1] * 1000 / 600;
uint32 endTime = args[2] * 1000 / 600;
// Track down our hotspot
Common::String hotspotName = Common::String::format("touchBook%d", args[3]);
RivenHotspot *hotspot = _vm->getCard()->getHotspotByName(hotspotName);
Common::Rect hotspotRect = hotspot->getRect();
debug(0, "xbookclick:");
debug(0, "\tVideo Code = %d", args[0]);
debug(0, "\tStart Time = %dms", startTime);
debug(0, "\tEnd Time = %dms", endTime);
debug(0, "\tHotspot = %d -> %s", args[3], hotspotName.c_str());
// Just let the video play while we wait until Gehn opens the trap book for us
while (video->getTime() < startTime && !_vm->hasGameEnded()) {
_vm->doFrame();
}
// Break out if we're quitting
if (_vm->hasGameEnded())
return;
// OK, Gehn has opened the trap book and has asked us to go in. Let's watch
// and see what the player will do...
while (video->getTime() < endTime && !_vm->hasGameEnded()) {
if (hotspotRect.contains(getMousePosition()))
_vm->_cursor->setCursor(kRivenOpenHandCursor);
else
_vm->_cursor->setCursor(kRivenMainCursor);
if (mouseIsDown()) {
if (hotspotRect.contains(getMousePosition())) {
// OK, we've used the trap book! We go for ride lady!
_vm->_video->closeVideos(); // Stop all videos
_vm->_cursor->setCursor(kRivenHideCursor); // Hide the cursor
_vm->_gfx->scheduleTransition(kRivenTransitionBlend);
_vm->getCard()->drawPicture(3); // Black out the screen
_vm->_sound->playSound(0); // Play the link sound
_vm->delay(12000);
_vm->getCard()->playMovie(7); // Activate Gehn Link Video
RivenVideo *linkVideo = _vm->_video->openSlot(1); // Play Gehn Link Video
linkVideo->playBlocking();
_vm->_vars["ocage"] = 1;
_vm->_vars["agehn"] = 4; // Set Gehn to the trapped state
_vm->_vars["atrapbook"] = 1; // We've got the trap book again
_vm->_sound->playSound(0); // Play the link sound again
_vm->_gfx->scheduleTransition(kRivenTransitionBlend);
_vm->changeToCard(_vm->getStack()->getCardStackId(0x2885)); // Link out!
_vm->_inventory->forceVisible(true);
_vm->delay(2000);
_vm->_inventory->forceVisible(false);
_vm->_scriptMan->stopAllScripts(); // Stop all running scripts (so we don't remain in the cage)
return;
}
}
_vm->doFrame();
}
// Break out if we're quitting
if (_vm->hasGameEnded())
return;
// If there was no click and this is the third time Gehn asks us to
// use the trap book, he will shoot the player. Dead on arrival.
// Run the credits from here.
if (_vm->_vars["agehn"] == 3) {
_vm->_scriptMan->stopAllScripts();
runCredits(args[0], 5000);
return;
}
// There was no click, so just play the rest of the video.
video->playBlocking();
}
示例5: loadSounds
void MinigameBbAnt::loadSounds() {
for (uint i = 0; i < kSoundFilenamesCount; ++i) {
Common::String filename = Common::String::format("bbant/%s", kSoundFilenames[i]);
_vm->_sound->loadSound(filename.c_str());
}
}
示例6:
const char *slide() const {
return _slide.c_str();
}
示例7: dir
// TODO: specify the possible return values here
static Common::Error runGame(const EnginePlugin *plugin, OSystem &system, const Common::String &edebuglevels) {
// Determine the game data path, for validation and error messages
Common::FSNode dir(ConfMan.get("path"));
Common::Error err = Common::kNoError;
Engine *engine = 0;
// Verify that the game path refers to an actual directory
if (!(dir.exists() && dir.isDirectory()))
err = Common::kPathNotDirectory;
// Create the game engine
if (err.getCode() == Common::kNoError)
err = (*plugin)->createInstance(&system, &engine);
// Check for errors
if (!engine || err.getCode() != Common::kNoError) {
// Print a warning; note that scummvm_main will also
// display an error dialog, so we don't have to do this here.
warning("%s failed to instantiate engine: %s (target '%s', path '%s')",
plugin->getName(),
err.getDesc().c_str(),
ConfMan.getActiveDomainName().c_str(),
dir.getPath().c_str()
);
// Autoadded is set only when no path was provided and
// the game is run from command line.
//
// Thus, we remove this garbage entry
//
// Fixes bug #1544799
if (ConfMan.hasKey("autoadded")) {
ConfMan.removeGameDomain(ConfMan.getActiveDomainName().c_str());
}
return err;
}
// Set the window caption to the game name
Common::String caption(ConfMan.get("description"));
if (caption.empty()) {
caption = EngineMan.findGame(ConfMan.get("gameid")).description();
}
if (caption.empty())
caption = ConfMan.getActiveDomainName(); // Use the domain (=target) name
if (!caption.empty()) {
system.setWindowCaption(caption.c_str());
}
//
// Setup various paths in the SearchManager
//
// Add the game path to the directory search list
SearchMan.addDirectory(dir.getPath(), dir, 0, 4);
// Add extrapath (if any) to the directory search list
if (ConfMan.hasKey("extrapath")) {
dir = Common::FSNode(ConfMan.get("extrapath"));
SearchMan.addDirectory(dir.getPath(), dir);
}
// If a second extrapath is specified on the app domain level, add that as well.
if (ConfMan.hasKey("extrapath", Common::ConfigManager::kApplicationDomain)) {
dir = Common::FSNode(ConfMan.get("extrapath", Common::ConfigManager::kApplicationDomain));
SearchMan.addDirectory(dir.getPath(), dir);
}
// On creation the engine should have set up all debug levels so we can use
// the command line arugments here
Common::StringTokenizer tokenizer(edebuglevels, " ,");
while (!tokenizer.empty()) {
Common::String token = tokenizer.nextToken();
if (!DebugMan.enableDebugChannel(token))
warning(_("Engine does not support debug level '%s'"), token.c_str());
}
// Inform backend that the engine is about to be run
system.engineInit();
// Run the engine
Common::Error result = engine->run();
// Inform backend that the engine finished
system.engineDone();
// Free up memory
delete engine;
// We clear all debug levels again even though the engine should do it
DebugMan.clearAllDebugChannels();
// Reset the file/directory mappings
SearchMan.clear();
// Return result (== 0 means no error)
return result;
//.........这里部分代码省略.........
示例8: restore
Common::Error Saver::restore(int slot) {
assert(!getMacroRestoreFlag());
Common::StackLock slock1(g_globals->_soundManager._serverDisabledMutex);
// Signal any objects registered for notification
_loadNotifiers.notify(false);
// Set fields
_macroRestoreFlag = true;
_saveSlot = slot;
_unresolvedPtrs.clear();
// Set up the serializer
Common::InSaveFile *saveFile = g_system->getSavefileManager()->openForLoading(g_vm->generateSaveName(slot));
if (!saveFile)
return Common::kReadingFailed;
Serializer serializer(saveFile, NULL);
// Read in the savegame header
tSageSavegameHeader header;
readSavegameHeader(saveFile, header);
if (header.thumbnail)
header.thumbnail->free();
delete header.thumbnail;
serializer.setSaveVersion(header.version);
// Load in data for objects that need to come at the start of the savegame
for (Common::List<SaveListener *>::iterator i = _listeners.begin(); i != _listeners.end(); ++i) {
(*i)->listenerSynchronize(serializer);
}
// Loop through each registered object to load in the data
for (SynchronizedList<SavedObject *>::iterator i = _objList.begin(); i != _objList.end(); ++i) {
serializer.validate((*i)->getClassName());
(*i)->synchronize(serializer);
}
// Loop through the remaining data of the file, instantiating new objects.
// Note: I don't store pointers to instantiated objects here, because it's not necessary - the mere act
// of instantiating a saved object registers it with the saver, and will then be resolved to whatever
// object originally had a pointer to it as part of the post-processing step
Common::String className;
serializer.syncString(className);
while (className != "END") {
SavedObject *savedObject;
if (!_factoryPtr || ((savedObject = _factoryPtr(className)) == NULL))
error("Unknown class name '%s' encountered trying to restore savegame", className.c_str());
// Populate the contents of the object
savedObject->synchronize(serializer);
// Move to next object
serializer.syncString(className);
}
// Post-process any unresolved pointers to get the correct pointer
resolveLoadPointers();
delete saveFile;
// Final post-restore notifications
_macroRestoreFlag = false;
_loadNotifiers.notify(true);
return Common::kNoError;
}
示例9: getSciLanguageString
Common::String SciEngine::getSciLanguageString(const Common::String &str, kLanguage requestedLanguage, kLanguage *secondaryLanguage, uint16 *languageSplitter) const {
kLanguage foundLanguage = K_LANG_NONE;
const byte *textPtr = (const byte *)str.c_str();
byte curChar = 0;
byte curChar2 = 0;
while (1) {
curChar = *textPtr;
if (!curChar)
break;
if ((curChar == '%') || (curChar == '#')) {
curChar2 = *(textPtr + 1);
foundLanguage = charToLanguage(curChar2);
if (foundLanguage != K_LANG_NONE) {
// Return language splitter
if (languageSplitter)
*languageSplitter = curChar | ( curChar2 << 8 );
// Return the secondary language found in the string
if (secondaryLanguage)
*secondaryLanguage = foundLanguage;
break;
}
}
textPtr++;
}
if (foundLanguage == requestedLanguage) {
if (curChar2 == 'J') {
// Japanese including Kanji, displayed with system font
// Convert half-width characters to full-width equivalents
Common::String fullWidth;
uint16 mappedChar;
textPtr += 2; // skip over language splitter
while (1) {
curChar = *textPtr;
switch (curChar) {
case 0: // Terminator NUL
return fullWidth;
case '\\':
// "\n", "\N", "\r" and "\R" were overwritten with SPACE + 0x0D in PC-9801 SSCI
// inside GetLongest() (text16). We do it here, because it's much cleaner and
// we have to process the text here anyway.
// Occurs for example in Police Quest 2 intro
curChar2 = *(textPtr + 1);
switch (curChar2) {
case 'n':
case 'N':
case 'r':
case 'R':
fullWidth += ' ';
fullWidth += 0x0D; // CR
textPtr += 2;
continue;
}
}
textPtr++;
mappedChar = s_halfWidthSJISMap[curChar];
if (mappedChar) {
fullWidth += mappedChar >> 8;
fullWidth += mappedChar & 0xFF;
} else {
// Copy double-byte character
curChar2 = *(textPtr++);
if (!curChar) {
error("SJIS character %02X is missing second byte", curChar);
break;
}
fullWidth += curChar;
fullWidth += curChar2;
}
}
} else {
示例10: isValidDomainName
static bool isValidDomainName(const Common::String &domName) {
const char *p = domName.c_str();
while (*p && (Common::isAlnum(*p) || *p == '-' || *p == '_'))
p++;
return *p == 0;
}
示例11: loadResourceFile
void MohawkEngine_CSTime::loadResourceFile(Common::String name) {
MohawkArchive *archive = new MohawkArchive();
if (!archive->open(name + ".mhk"))
error("failed to open %s.mhk", name.c_str());
_mhk.push_back(archive);
}
示例12: getParamByte
void ScriptLifeV1::SAY_MESSAGE_OBJ() {
byte actor = getParamByte();
uint16 id = getParamUint16();
Common::String str = g_resource->getMessage(0, id);
warning("STUB: SAY_MESSAGE_OBJ(%d): %s", id, str.c_str());
}
示例13: getSavegameFilename
const char *ToltecsEngine::getSavegameFilename(int num) {
static Common::String filename;
filename = getSavegameFilename(_targetName, num);
return filename.c_str();
}
示例14: saveGameState
Common::Error ToltecsEngine::saveGameState(int slot, const Common::String &description) {
const char *fileName = getSavegameFilename(slot);
savegame(fileName, description.c_str());
return Common::kNoError;
}
示例15: hasFile
bool NSArchive::hasFile(const Common::String &name) const {
if (name.empty())
return false;
return lookup(name.c_str()) != _numFiles;
}