本文整理汇总了C++中common::String::hasPrefix方法的典型用法代码示例。如果您正苦于以下问题:C++ String::hasPrefix方法的具体用法?C++ String::hasPrefix怎么用?C++ String::hasPrefix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common::String
的用法示例。
在下文中一共展示了String::hasPrefix方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: listDirectory
bool FilesPageHandler::listDirectory(Common::String path, Common::String &content, const Common::String &itemTemplate) {
if (path == "" || path == "/") {
if (ConfMan.hasKey("rootpath", "cloud"))
addItem(content, itemTemplate, IT_DIRECTORY, "/root/", _("File system root"));
addItem(content, itemTemplate, IT_DIRECTORY, "/saves/", _("Saved games"));
return true;
}
if (HandlerUtils::hasForbiddenCombinations(path))
return false;
Common::String prefixToRemove = "", prefixToAdd = "";
if (!transformPath(path, prefixToRemove, prefixToAdd))
return false;
Common::FSNode node = Common::FSNode(path);
if (path == "/")
node = node.getParent(); // absolute root
if (!HandlerUtils::permittedPath(node.getPath()))
return false;
if (!node.isDirectory())
return false;
// list directory
Common::FSList _nodeContent;
if (!node.getChildren(_nodeContent, Common::FSNode::kListAll, false)) // do not show hidden files
_nodeContent.clear();
else
Common::sort(_nodeContent.begin(), _nodeContent.end());
// add parent directory link
{
Common::String filePath = path;
if (filePath.hasPrefix(prefixToRemove))
filePath.erase(0, prefixToRemove.size());
if (filePath == "" || filePath == "/" || filePath == "\\")
filePath = "/";
else
filePath = parentPath(prefixToAdd + filePath);
addItem(content, itemTemplate, IT_PARENT_DIRECTORY, filePath, _("Parent directory"));
}
// fill the content
for (Common::FSList::iterator i = _nodeContent.begin(); i != _nodeContent.end(); ++i) {
Common::String name = i->getDisplayName();
if (i->isDirectory())
name += "/";
Common::String filePath = i->getPath();
if (filePath.hasPrefix(prefixToRemove))
filePath.erase(0, prefixToRemove.size());
filePath = prefixToAdd + filePath;
addItem(content, itemTemplate, detectType(i->isDirectory(), name), filePath, name);
}
return true;
}
示例2: parse
bool PlayAnimationCommandParser::parse(const Common::String &line, ScriptParseContext &parseCtx, Command *&command) {
if (line.size() < 11 || (!line.hasPrefix("FLB ") && !line.hasPrefix("FLX ")))
return false;
const int fromFrame = atoi(line.c_str() + 4);
const int toFrame = atoi(line.c_str() + 8);
command = new PlayAnimationCommand(fromFrame, toFrame);
return true;
}
示例3: handleFanmadeSciAudio
/**
* Handles the sciAudio calls in fanmade games.
* sciAudio is an external .NET library for playing MP3 files in fanmade games.
* It runs in the background, and obtains sound commands from the
* currently running game via text files (called "conductor files").
* For further info, check: http://sciprogramming.com/community/index.php?topic=634.0
*/
void AudioPlayer::handleFanmadeSciAudio(reg_t sciAudioObject, SegManager *segMan) {
// TODO: This is a bare bones implementation. Only the play/playx and stop commands
// are handled for now - the other commands haven't been observed in any fanmade game
// yet. All the volume related and fading functionality is currently missing.
Kernel *kernel = g_sci->getKernel();
reg_t commandReg = readSelector(segMan, sciAudioObject, kernel->findSelector("command"));
Common::String command = segMan->getString(commandReg);
if (command == "play" || command == "playx") {
#ifdef USE_MAD
reg_t fileNameReg = readSelector(segMan, sciAudioObject, kernel->findSelector("fileName"));
Common::String fileName = segMan->getString(fileNameReg);
int16 loopCount = (int16)readSelectorValue(segMan, sciAudioObject, kernel->findSelector("loopCount"));
// When loopCount is -1, we treat it as infinite looping, else no looping is done.
// This is observed by game scripts, which can set loopCount to all sorts of random values.
// Adjust loopCount for ScummVM's LoopingAudioStream semantics
loopCount = (loopCount == -1) ? 0 : 1;
// Determine sound type
Audio::Mixer::SoundType soundType = Audio::Mixer::kSFXSoundType;
if (fileName.hasPrefix("music"))
soundType = Audio::Mixer::kMusicSoundType;
else if (fileName.hasPrefix("speech"))
soundType = Audio::Mixer::kSpeechSoundType;
Common::File *sciAudio = new Common::File();
// Replace backwards slashes
for (uint i = 0; i < fileName.size(); i++) {
if (fileName[i] == '\\')
fileName.setChar('/', i);
}
sciAudio->open("sciAudio/" + fileName);
Audio::SeekableAudioStream *audioStream = Audio::makeMP3Stream(sciAudio, DisposeAfterUse::YES);
// We only support one audio handle
_mixer->playStream(soundType, &_audioHandle,
Audio::makeLoopingAudioStream((Audio::RewindableAudioStream *)audioStream, loopCount));
#endif
} else if (command == "stop") {
_mixer->stopHandle(_audioHandle);
} else {
warning("Unhandled sciAudio command: %s", command.c_str());
}
}
示例4: mangleFilename
Common::String ComposerEngine::mangleFilename(Common::String filename) {
while (filename.size() && (filename[0] == '~' || filename[0] == ':' || filename[0] == '\\'))
filename = filename.c_str() + 1;
uint slashesToStrip = _directoriesToStrip;
if (filename.hasPrefix(".."))
slashesToStrip = 1;
while (slashesToStrip--) {
for (uint i = 0; i < filename.size(); i++) {
if (filename[i] != '\\' && filename[i] != ':')
continue;
filename = filename.c_str() + i + 1;
break;
}
}
Common::String outFilename;
for (uint i = 0; i < filename.size(); i++) {
if (filename[i] == '\\' || filename[i] == ':')
outFilename += '/';
else
outFilename += filename[i];
}
return outFilename;
}
示例5: Sword1CheckDirectory
void Sword1CheckDirectory(const Common::FSList &fslist, bool *filesFound, bool recursion = false) {
for (Common::FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
if (!file->isDirectory()) {
// The required game data files can be located in the game directory, or in
// a subdirectory called "clusters". In the latter case, we don't want to
// detect the game in that subdirectory, as this will detect the game twice
// when mass add is searching inside a directory. In this case, the first
// result (the game directory) will be correct, but the second result (the
// clusters subdirectory) will be wrong, as the optional speech, music and
// video data files will be ignored. Note that this fix will skip the game
// data files if the user has placed them inside a "clusters" subdirectory,
// or if he/she points ScummVM directly to the "clusters" directory of the
// game CD. Fixes bug #3049346.
Common::String directory = file->getParent().getName();
directory.toLowercase();
if (directory.hasPrefix("clusters") && directory.size() <= 9 && !recursion)
continue;
const char *fileName = file->getName().c_str();
for (int cnt = 0; cnt < NUM_FILES_TO_CHECK; cnt++)
if (scumm_stricmp(fileName, g_filesToCheck[cnt]) == 0)
filesFound[cnt] = true;
} else {
for (int cnt = 0; cnt < ARRAYSIZE(g_dirNames); cnt++)
if (scumm_stricmp(file->getName().c_str(), g_dirNames[cnt]) == 0) {
Common::FSList fslist2;
if (file->getChildren(fslist2, Common::FSNode::kListFilesOnly))
Sword1CheckDirectory(fslist2, filesFound, true);
}
}
}
}
示例6: loadFile
bool BaseImage::loadFile(const Common::String &filename) {
_filename = filename;
_filename.toLowercase();
if (filename.hasPrefix("savegame:") || _filename.hasSuffix(".bmp")) {
_decoder = new Image::BitmapDecoder();
} else if (_filename.hasSuffix(".png")) {
_decoder = new Image::PNGDecoder();
} else if (_filename.hasSuffix(".tga")) {
_decoder = new Image::TGADecoder();
} else if (_filename.hasSuffix(".jpg")) {
_decoder = new Image::JPEGDecoder();
} else {
error("BaseImage::loadFile : Unsupported fileformat %s", filename.c_str());
}
_filename = filename;
Common::SeekableReadStream *file = _fileManager->openFile(filename.c_str());
if (!file) {
return false;
}
_decoder->loadStream(*file);
_surface = _decoder->getSurface();
_palette = _decoder->getPalette();
_fileManager->closeFile(file);
return true;
}
示例7: ensureSpeechLang
Common::String PackageManager::ensureSpeechLang(const Common::String &fileName) {
if (!_useEnglishSpeech || fileName.size() < 9 || !fileName.hasPrefix("/speech/"))
return fileName;
// Always keep German speech as a fallback in case the English speech pack is not present.
// However this means we cannot play with German text and English voice.
if (fileName.hasPrefix("/speech/de"))
return fileName;
Common::String newFileName = "/speech/en";
int fileIdx = 9;
while (fileIdx < fileName.size() && fileName[fileIdx] != '/')
++fileIdx;
if (fileIdx < fileName.size())
newFileName += fileName.c_str() + fileIdx;
return newFileName;
}
示例8: lastPathComponent
WindowsFilesystemNode::WindowsFilesystemNode(const Common::String &p, const bool currentDir) {
if (currentDir) {
char path[MAX_PATH];
GetCurrentDirectory(MAX_PATH, path);
_path = path;
} else {
assert(p.size() > 0);
#ifndef _WIN32_WCE
_path = p;
#else
// Check whether p is a relative path
if (p.hasPrefix("\\") || p.hasPrefix("/")) {
_path = p;
} else {
// Add current directory as a prefix to the path
// (Windows CE has no concept for relative paths)
char path[MAX_PATH];
GetCurrentDirectory(MAX_PATH, path);
_path = path;
_path += '\\';
_path += p;
}
#endif
}
_displayName = lastPathComponent(_path, '\\');
// Check whether it is a directory, and whether the file actually exists
DWORD fileAttribs = GetFileAttributes(toUnicode(_path.c_str()));
if (fileAttribs == INVALID_FILE_ATTRIBUTES) {
_isDirectory = false;
_isValid = false;
} else {
_isDirectory = ((fileAttribs & FILE_ATTRIBUTE_DIRECTORY) != 0);
_isValid = true;
// Add a trailing slash, if necessary.
if (_isDirectory && _path.lastChar() != '\\') {
_path += '\\';
}
}
_isPseudoRoot = false;
}
示例9: readSavegameThumbnail
RenderedImage::RenderedImage(const Common::String &filename, bool &result) :
_data(0),
_width(0),
_height(0),
_isTransparent(true) {
result = false;
PackageManager *pPackage = Kernel::getInstance()->getPackage();
assert(pPackage);
_backSurface = Kernel::getInstance()->getGfx()->getSurface();
// Load file
byte *pFileData;
uint fileSize;
bool isPNG = true;
if (filename.hasPrefix("/saves")) {
pFileData = readSavegameThumbnail(filename, fileSize, isPNG);
} else {
pFileData = pPackage->getFile(filename, &fileSize);
}
if (!pFileData) {
error("File \"%s\" could not be loaded.", filename.c_str());
return;
}
// Uncompress the image
int pitch;
if (isPNG)
result = ImgLoader::decodePNGImage(pFileData, fileSize, _data, _width, _height, pitch);
else
result = ImgLoader::decodeThumbnailImage(pFileData, fileSize, _data, _width, _height, pitch);
if (!result) {
error("Could not decode image.");
delete[] pFileData;
return;
}
// Cleanup FileData
delete[] pFileData;
_doCleanup = true;
#if defined(SCUMM_LITTLE_ENDIAN)
// Makes sense for LE only at the moment
checkForTransparency();
#endif
return;
}
示例10: translateFileName
Common::String Resource::translateFileName(const Common::String filename) {
Common::String upperFilename = filename;
upperFilename.toUppercase();
Common::String fileNameStrFinal;
if (upperFilename.hasPrefix("P:") || upperFilename.hasPrefix("F:")) {
if (_vm->_isHiRes)
fileNameStrFinal = "SPICT/";
else
fileNameStrFinal = "PICT/";
if (_vm->getPlatform() == Common::kPlatformAmiga) {
if (upperFilename.hasPrefix("P:")) {
fileNameStrFinal = "PICT/";
} else {
fileNameStrFinal = "LABFONTS/";
upperFilename += "T"; // all the Amiga fonts have a ".FONT" suffix
}
}
} else if (upperFilename.hasPrefix("LAB:")) {
// Look inside the game folder
} else if (upperFilename.hasPrefix("MUSIC:")) {
fileNameStrFinal = "MUSIC/";
}
if (upperFilename.contains(':')) {
while (upperFilename[0] != ':') {
upperFilename.deleteChar(0);
}
upperFilename.deleteChar(0);
}
fileNameStrFinal += upperFilename;
return fileNameStrFinal;
}
示例11: unpersist
bool StaticBitmap::unpersist(InputPersistenceBlock &reader) {
bool result = true;
result &= Bitmap::unpersist(reader);
Common::String resourceFilename;
reader.readString(resourceFilename);
// We may not have saves, and we actually do not need to
// restore them. So do not even try to load them.
if (!resourceFilename.hasPrefix("/saves"))
result &= initBitmapResource(resourceFilename);
result &= RenderObject::unpersistChildren(reader);
return reader.isGood() && result;
}
示例12: parse
bool ChangeSceneCommandParser::parse(const Common::String &line, ScriptParseContext &, Command *&command) {
if (!line.hasPrefix("CHANGE ")) {
return false;
}
uint8 sceneId = 0;
uint8 objectId = 0;
ChangeCommand::ChangeRegister reg;
ChangeCommand::ChangeOperation op;
ChangeCommandValue val;
if (!parseValueString(line.c_str() + 7, false, sceneId, objectId, reg, op, val)) {
return false;
}
command = new ChangeSceneCommand(sceneId, objectId, reg, op, val);
return true;
}
示例13: getenv
POSIXFilesystemNode::POSIXFilesystemNode(const Common::String &p) {
assert(p.size() > 0);
// Expand "~/" to the value of the HOME env variable
if (p.hasPrefix("~/")) {
const char *home = getenv("HOME");
if (home != NULL && strlen(home) < MAXPATHLEN) {
_path = home;
// Skip over the tilda. We know that p contains at least
// two chars, so this is safe:
_path += p.c_str() + 1;
}
} else {
_path = p;
}
#ifdef __OS2__
// On OS/2, 'X:/' is a root of drive X, so we should not remove that last
// slash.
if (!(_path.size() == 3 && _path.hasSuffix(":/")))
#endif
// Normalize the path (that is, remove unneeded slashes etc.)
_path = Common::normalizePath(_path, '/');
_displayName = Common::lastPathComponent(_path, '/');
// TODO: should we turn relative paths into absolute ones?
// Pro: Ensures the "getParent" works correctly even for relative dirs.
// Contra: The user may wish to use (and keep!) relative paths in his
// config file, and converting relative to absolute paths may hurt him...
//
// An alternative approach would be to change getParent() to work correctly
// if "_path" is the empty string.
#if 0
if (!_path.hasPrefix("/")) {
char buf[MAXPATHLEN+1];
getcwd(buf, MAXPATHLEN);
strcat(buf, "/");
_path = buf + _path;
}
#endif
// TODO: Should we enforce that the path is absolute at this point?
//assert(_path.hasPrefix("/"));
setFlags();
}
示例14:
GBAMPFileSystemNode::GBAMPFileSystemNode(const Common::String& path) {
// consolePrintf("'%s'",path.c_str());
int lastSlash = 3;
for (int r = 0; r < (int) path.size() - 1; r++) {
if ((path[r] == '\\') || (path[r] == '/')) {
lastSlash = r;
}
}
if (path == "mp:/") {
// This is the root directory
_isDirectory = true;
_isValid = false; // Old code returned false here, but I'm not sure why
} else {
char check[128];
memset(check, 0, 128);
if (path.size() > 4 && path.hasPrefix("mp:/")) {
// Files which start with mp:/
// Clear the filename to 128 bytes, because a libfat bug occasionally tries to read in this area.
strcpy(check, path.c_str() + 3);
} else {
// Clear the filename to 128 bytes, because a libfat bug occationally tries to read in this area.
strcpy(check, path.c_str());
}
// Remove terminating slash - FileExists fails without this
if (check[strlen(check) - 1] == '/') {
check[strlen(check) - 1] = 0;
}
int fileOrDir = FAT_FileExists(check);
_isDirectory = fileOrDir == FT_DIR;
_isValid = fileOrDir == FT_FILE;
}
// consolePrintf("Path: %s \n", check);
_displayName = Common::String(path.c_str() + lastSlash + 1);
_path = path;
}
示例15: Cmd_PlayText
bool Debugger::Cmd_PlayText(int argc, const char **argv) {
if (argc != 2) {
debugPrintf("Usage: %s <text name>\n", argv[0]);
return true;
} else {
Common::String resName = argv[1];
if (resName.hasPrefix("@"))
resName.deleteChar(0);
Common::File f;
if (f.exists(resName) || f.exists(resName + ".txr")) {
TextView::execute(_vm, resName);
return false;
} else {
debugPrintf("Could not find resource file\n");
return true;
}
}
}