本文整理汇总了C++中String类的典型用法代码示例。如果您正苦于以下问题:C++ String类的具体用法?C++ String怎么用?C++ String使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了String类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getText
String
XMLText::nodeNotFound(const String& nodeName) const
{
return getText("Node (%s) not found",
nodeName.c_str());
}
示例2: ProjLoad_fillProjectVarsInSourceFiles
void ProjLoad_fillProjectVarsInSourceFiles(StringTree&sourceTree, const String&templateSrcRoot, const String&projectSrcRoot, const String&subFolder,
const String&projectName, const String&authorName, const String&projectNameAsIdentifier,
const String&executableName, const String& productName)
{
ArrayList<String> members = sourceTree.getMembers();
String templateSrcCurrentFolder = templateSrcRoot;
String projectSrcCurrentFolder = projectSrcRoot;
if(!subFolder.equals(""))
{
templateSrcCurrentFolder += (String)"/" + subFolder;
projectSrcCurrentFolder += (String)"/" + subFolder;
}
for(int i=0; i<members.size(); i++)
{
String filename = members.get(i);
String filepath = templateSrcCurrentFolder + '/' + filename;
String fileContents;
bool loadedFile = FileTools::loadFileIntoString(filepath, fileContents);
if(!loadedFile)
{
showSimpleMessageBox("Error loading ProjectData", (String)"Error loading file " + filepath);
}
else
{
ProjLoad_fillProjectVarsInString(fileContents, projectName, authorName, projectNameAsIdentifier, executableName, productName);
String newFilename = filename;
ProjLoad_fillProjectVarsInString(newFilename, projectName, authorName, projectNameAsIdentifier, executableName, productName);
String saveFile = newFilename;
//rename file if necessary
bool couldRename = false;
int matchChecks = 0;
do
{
couldRename = sourceTree.renameMember(filename, saveFile);
if(!couldRename)
{
matchChecks++;
saveFile = newFilename + " (" + matchChecks + ')';
}
}
while (!couldRename);
bool success = FileTools::writeStringToFile(projectSrcCurrentFolder + '/' + saveFile, fileContents);
if(!success)
{
showSimpleMessageBox("Error creating new project", (String)"Error creating file " + projectSrcCurrentFolder + '/' + saveFile);
}
}
}
ArrayList<String> branchNames = sourceTree.getBranchNames();
for(int i=0; i<branchNames.size(); i++)
{
String branchname = branchNames.get(i);
String branchpath = templateSrcCurrentFolder + '/' + branchname;
String newBranchname = branchname;
ProjLoad_fillProjectVarsInString(newBranchname, projectName, authorName, projectNameAsIdentifier, executableName, productName);
String saveFolder = newBranchname;
//rename file if necessary
bool couldRename = false;
int matchChecks = 0;
do
{
couldRename = sourceTree.renameBranch(branchname, saveFolder);
if(!couldRename)
{
matchChecks++;
saveFolder = newBranchname + " (" + matchChecks + ')';
}
}
while (!couldRename);
bool success = FileTools::createDirectory(projectSrcCurrentFolder + '/' + saveFolder);
if(success)
{
StringTree*tree = sourceTree.getBranch(saveFolder);
ProjLoad_fillProjectVarsInSourceFiles(*tree, templateSrcRoot, projectSrcRoot, subFolder + '/' + saveFolder,
projectName, authorName, projectNameAsIdentifier, executableName, productName);
}
else
{
showSimpleMessageBox("Error creating new project", (String)"Error creating folder " + projectSrcCurrentFolder + '/' + saveFolder);
}
}
}
示例3: setText
void TextBox::setText(String t)
{
txt_len = t.len();
strcpy(&txt[0], t.ptr());
}
示例4: HHVM_FUNCTION
static Array HHVM_FUNCTION(getopt, const String& options,
const Variant& longopts /*=null */) {
opt_struct *opts, *orig_opts;
int len = parse_opts(options.data(), options.size(), &opts);
if (!longopts.isNull()) {
Array arropts = longopts.toArray();
int count = arropts.size();
/* the first <len> slots are filled by the one short ops
* we now extend our array and jump to the new added structs */
opts = (opt_struct *)realloc(opts, sizeof(opt_struct) * (len + count + 1));
orig_opts = opts;
opts += len;
memset(opts, 0, count * sizeof(opt_struct));
for (ArrayIter iter(arropts); iter; ++iter) {
String entry = iter.second().toString();
opts->need_param = 0;
opts->opt_name = strdup(entry.data());
len = strlen(opts->opt_name);
if ((len > 0) && (opts->opt_name[len - 1] == ':')) {
opts->need_param++;
opts->opt_name[len - 1] = '\0';
if ((len > 1) && (opts->opt_name[len - 2] == ':')) {
opts->need_param++;
opts->opt_name[len - 2] = '\0';
}
}
opts->opt_char = 0;
opts++;
}
} else {
opts = (opt_struct*) realloc(opts, sizeof(opt_struct) * (len + 1));
orig_opts = opts;
opts += len;
}
/* php_getopt want to identify the last param */
opts->opt_char = '-';
opts->need_param = 0;
opts->opt_name = NULL;
static const StaticString s_argv("argv");
Array vargv = php_global(s_argv).toArray();
int argc = vargv.size();
char **argv = (char **)malloc((argc+1) * sizeof(char*));
std::vector<String> holders;
int index = 0;
for (ArrayIter iter(vargv); iter; ++iter) {
String arg = iter.second().toString();
holders.push_back(arg);
argv[index++] = (char*)arg.data();
}
argv[index] = NULL;
/* after our pointer arithmetic jump back to the first element */
opts = orig_opts;
int o;
char *php_optarg = NULL;
int php_optind = 1;
SCOPE_EXIT {
free_longopts(orig_opts);
free(orig_opts);
free(argv);
};
Array ret = Array::Create();
Variant val;
int optchr = 0;
int dash = 0; /* have already seen the - */
char opt[2] = { '\0' };
char *optname;
int optname_len = 0;
int php_optidx;
while ((o = php_getopt(argc, argv, opts, &php_optarg, &php_optind, 0, 1,
optchr, dash, php_optidx))
!= -1) {
/* Skip unknown arguments. */
if (o == '?') {
continue;
}
/* Prepare the option character and the argument string. */
if (o == 0) {
optname = opts[php_optidx].opt_name;
} else {
if (o == 1) {
o = '-';
}
opt[0] = o;
optname = opt;
}
if (php_optarg != NULL) {
//.........这里部分代码省略.........
示例5: setCertificatePath
void MediaPlayerPrivate::setCertificatePath(const String& caPath)
{
MMRPlayer::setCertificatePath(string(caPath.utf8().data()));
}
示例6: main
int main(int argc, char* argv[])
{
try
{
String url;
String ns;
String classname;
// handle backwards compatible options, which was <URL> <namespace> <classname>
// TODO: This is deprecated in 3.1.0, remove it post 3.1
if (argc == 4 && argv[1][0] != '-' && argv[2][0] != '-' && argv[3][0] != '-')
{
url = argv[1];
ns = argv[2];
classname = argv[3];
cerr << "This cmd line usage is deprecated!\n";
}
else
{
CmdLineParser parser(argc, argv, g_options, CmdLineParser::E_NON_OPTION_ARGS_INVALID);
if (parser.isSet(HELP_OPT))
{
Usage();
return 0;
}
else if (parser.isSet(VERSION_OPT))
{
cout << "owenumclassnames (OpenWBEM) " << OW_VERSION << '\n';
cout << "Written by Dan Nuffer.\n";
return 0;
}
url = parser.getOptionValue(URL_OPT, "http://localhost/root/cimv2");
ns = URL(url).namespaceName;
if (ns.empty())
{
cerr << "No namespace given as part of the url." << endl;
Usage();
return 1;
}
classname = parser.getOptionValue(CLASSNAME_OPT);
}
ClientAuthCBIFCRef getLoginInfo(new GetLoginInfo);
ClientCIMOMHandleRef rch = ClientCIMOMHandle::createFromURL(url, getLoginInfo);
classNamePrinter handler;
rch->enumClassNames(ns, classname, handler);
return 0;
}
catch (CmdLineParserException& e)
{
printCmdLineParserExceptionMessage(e);
Usage();
}
catch(const Exception& e)
{
cerr << e << endl;
}
catch(const std::exception& e)
{
cerr << e.what() << endl;
}
catch(...)
{
cerr << "Caught unknown exception in main" << endl;
}
return 1;
}
示例7: et
bool mm::parse(ID3_TagImpl& tag, ID3_Reader& rdr)
{
io::ExitTrigger et(rdr);
ID3_Reader::pos_type end = rdr.getCur();
if (end < rdr.getBeg() + 48)
{
ID3D_NOTICE( "mm::parse: bailing, not enough bytes to parse, pos = " << end );
return false;
}
rdr.setCur(end - 48);
String version;
{
if (io::readText(rdr, 32) != "Brava Software Inc. ")
{
ID3D_NOTICE( "mm::parse: bailing, couldn't find footer" );
return false;
}
version = io::readText(rdr, 4);
if (version.size() != 4 ||
!isdigit(version[0]) || version[1] != '.' ||
!isdigit(version[2]) ||
!isdigit(version[3]))
{
ID3D_WARNING( "mm::parse: bailing, nonstandard version = " << version );
return false;
}
}
ID3_Reader::pos_type beg = rdr.setCur(end - 48);
et.setExitPos(beg);
if (end < 68)
{
ID3D_NOTICE( "mm::parse: bailing, not enough bytes to parse offsets, pos = " << end );
return false;
}
rdr.setCur(end - 68);
io::WindowedReader dataWindow(rdr);
dataWindow.setEnd(rdr.getCur());
size_t offsets[5];
io::WindowedReader offsetWindow(rdr, 20);
for (size_t i = 0; i < 5; ++i)
{
offsets[i] = io::readLENumber(rdr, sizeof(uint32));
}
size_t metadataSize = 0;
if (version <= "3.00")
{
// All MusicMatch tags up to and including version 3.0 had metadata
// sections exactly 7868 bytes in length.
metadataSize = 7868;
}
else
{
// MusicMatch tags after version 3.0 had three possible lengths for their
// metadata sections. We can determine which it was by searching for
// the version section signature that should precede the metadata section
// by exactly 256 bytes.
size_t possibleSizes[] = { 8132, 8004, 7936 };
for (size_t i = 0; i < sizeof(possibleSizes)/sizeof(size_t); ++i)
{
dataWindow.setCur(dataWindow.getEnd());
// Our offset will be exactly 256 bytes prior to our potential metadata
// section
size_t offset = possibleSizes[i] + 256;
if (dataWindow.getCur() < offset)
{
// if our filesize is less than the offset, then it can't possibly
// be the correct offset, so try again.
continue;
}
dataWindow.setCur(dataWindow.getCur() - offset);
// now read in the signature to see if it's a match
if (io::readText(dataWindow, 8) == "18273645")
{
metadataSize = possibleSizes[i];
break;
}
}
}
if (0 == metadataSize)
{
// if we didn't establish a size for the metadata, then something is
// wrong. probably should log this.
ID3D_WARNING( "mm::parse: bailing, couldn't find meta data signature, end = " << end );
return false;
}
// parse the offset pointers to determine the actual sizes of all the
// sections
size_t sectionSizes[5];
//.........这里部分代码省略.........
示例8: GetProxy
DebuggerProxyPtr Debugger::GetProxy() {
SystemGlobals *g = (SystemGlobals*)get_global_variables();
String id = g->GV(_SERVER)["HPHP_SANDBOX_ID"];
return s_debugger.findProxy(id.data());
}
示例9: get_text_edit
void ScriptTextEditor::_load_theme_settings() {
get_text_edit()->clear_colors();
/* keyword color */
get_text_edit()->set_custom_bg_color(EDITOR_DEF("text_editor/background_color",Color(0,0,0,0)));
get_text_edit()->add_color_override("font_color",EDITOR_DEF("text_editor/text_color",Color(0,0,0)));
get_text_edit()->add_color_override("font_selected_color",EDITOR_DEF("text_editor/text_selected_color",Color(1,1,1)));
get_text_edit()->add_color_override("selection_color",EDITOR_DEF("text_editor/selection_color",Color(0.2,0.2,1)));
Color keyword_color= EDITOR_DEF("text_editor/keyword_color",Color(0.5,0.0,0.2));
get_text_edit()->set_syntax_coloring(true);
List<String> keywords;
script->get_language()->get_reserved_words(&keywords);
for(List<String>::Element *E=keywords.front();E;E=E->next()) {
get_text_edit()->add_keyword_color(E->get(),keyword_color);
}
//colorize core types
Color basetype_color= EDITOR_DEF("text_editor/base_type_color",Color(0.3,0.3,0.0));
get_text_edit()->add_keyword_color("Vector2",basetype_color);
get_text_edit()->add_keyword_color("Vector3",basetype_color);
get_text_edit()->add_keyword_color("Plane",basetype_color);
get_text_edit()->add_keyword_color("Quat",basetype_color);
get_text_edit()->add_keyword_color("AABB",basetype_color);
get_text_edit()->add_keyword_color("Matrix3",basetype_color);
get_text_edit()->add_keyword_color("Transform",basetype_color);
get_text_edit()->add_keyword_color("Color",basetype_color);
get_text_edit()->add_keyword_color("Image",basetype_color);
get_text_edit()->add_keyword_color("InputEvent",basetype_color);
//colorize engine types
Color type_color= EDITOR_DEF("text_editor/engine_type_color",Color(0.0,0.2,0.4));
List<String> types;
ObjectTypeDB::get_type_list(&types);
for(List<String>::Element *E=types.front();E;E=E->next()) {
get_text_edit()->add_keyword_color(E->get(),type_color);
}
//colorize comments
Color comment_color = EDITOR_DEF("text_editor/comment_color",Color::hex(0x797e7eff));
List<String> comments;
script->get_language()->get_comment_delimiters(&comments);
for(List<String>::Element *E=comments.front();E;E=E->next()) {
String comment = E->get();
String beg = comment.get_slice(" ",0);
String end = comment.get_slice_count(" ")>1?comment.get_slice(" ",1):String();
get_text_edit()->add_color_region(beg,end,comment_color,end=="");
}
//colorize strings
Color string_color = EDITOR_DEF("text_editor/string_color",Color::hex(0x6b6f00ff));
List<String> strings;
script->get_language()->get_string_delimiters(&strings);
for (List<String>::Element *E=strings.front();E;E=E->next()) {
String string = E->get();
String beg = string.get_slice(" ",0);
String end = string.get_slice_count(" ")>1?string.get_slice(" ",1):String();
get_text_edit()->add_color_region(beg,end,string_color,end=="");
}
//colorize symbols
Color symbol_color= EDITOR_DEF("text_editor/symbol_color",Color::hex(0x005291ff));
get_text_edit()->set_symbol_color(symbol_color);
}
示例10: read_rtc_time
uint32_t NexRtc::read_rtc_time(char *time,uint32_t len)
{
char time_buf[22] = {"0000/00/00 00:00:00 0"};
uint32_t year,mon,day,hour,min,sec,week;
String cmd;
cmd = "get rtc0";
sendCommand(cmd.c_str());
recvRetNumber(&year);
cmd = "";
cmd = "get rtc1";
sendCommand(cmd.c_str());
recvRetNumber(&mon);
cmd = "";
cmd = "get rtc2";
sendCommand(cmd.c_str());
recvRetNumber(&day);
cmd = "";
cmd = "get rtc3";
sendCommand(cmd.c_str());
recvRetNumber(&hour);
cmd = "";
cmd = "get rtc4";
sendCommand(cmd.c_str());
recvRetNumber(&min);
cmd = "";
cmd = "get rtc5";
sendCommand(cmd.c_str());
recvRetNumber(&sec);
cmd = "";
cmd = "get rtc6";
sendCommand(cmd.c_str());
recvRetNumber(&week);
time_buf[0] = year/1000 + '0';
time_buf[1] = (year/100)%10 + '0';
time_buf[2] = (year/10)%10 + '0';
time_buf[3] = year%10 + '0';
time_buf[5] = mon/10 + '0';
time_buf[6] = mon%10 + '0';
time_buf[8] = day/10 + '0';
time_buf[9] = day%10 + '0';
time_buf[11] = hour/10 + '0';
time_buf[12] = hour%10 + '0';
time_buf[14] = min/10 + '0';
time_buf[15] = min%10 + '0';
time_buf[17] = sec/10 + '0';
time_buf[18] = sec%10 + '0';
time_buf[20] = week + '0';
time_buf[21] = '\0';
if(len >= 22)
{
for(int i=0;i<22;i++)
{
time[i] = time_buf[i];
}
}
else{
for(int i=0;i<len;i++)
{
time[i] = time_buf[i];
}
}
}
示例11: fail
Result Result::fail (const String& errorMessage) noexcept
{
return Result (errorMessage.isEmpty() ? "Unknown Error" : errorMessage);
}
示例12: switch
void Item::toString( String &target ) const
{
target.size(0);
switch( this->type() )
{
case FLC_ITEM_NIL:
target = "Nil";
break;
case FLC_ITEM_UNB:
target = "_";
break;
case FLC_ITEM_BOOL:
target = asBoolean() ? "true" : "false";
break;
case FLC_ITEM_INT:
target.writeNumber( this->asInteger() );
break;
case FLC_ITEM_RANGE:
target = "[";
target.writeNumber( (int64) this->asRangeStart() );
target += ":";
if ( ! this->asRangeIsOpen() )
{
target.writeNumber( (int64) this->asRangeEnd() );
if ( this->asRangeStep() != 0 )
{
target += ":";
target.writeNumber( (int64) this->asRangeStep() );
}
}
target += "]";
break;
case FLC_ITEM_NUM:
{
target.writeNumber( this->asNumeric(), "%.16g" );
}
break;
case FLC_ITEM_MEMBUF:
target = "MemBuf( ";
target.writeNumber( (int64) this->asMemBuf()->length() );
target += ", ";
target.writeNumber( (int64) this->asMemBuf()->wordSize() );
target += " )";
break;
case FLC_ITEM_STRING:
target = *asString();
break;
case FLC_ITEM_LBIND:
if ( isFutureBind() )
{
String temp;
asFutureBind().toString(temp);
target = *asLBind() + "|" + temp;
}
else
target = "&" + *asLBind();
break;
case FLC_ITEM_REFERENCE:
dereference()->toString( target );
break;
case FLC_ITEM_OBJECT:
target = "Object from " + asObjectSafe()->generator()->symbol()->name();
break;
case FLC_ITEM_ARRAY:
target = "Array";
break;
case FLC_ITEM_DICT:
target = "Dictionary";
break;
case FLC_ITEM_FUNC:
target = "Function " + this->asFunction()->symbol()->name();
break;
case FLC_ITEM_CLASS:
target = "Class " + this->asClass()->symbol()->name();
break;
case FLC_ITEM_METHOD:
{
Item orig;
this->getMethodItem( orig );
String temp;
orig.dereference()->toString( temp );
target = "Method (" + temp + ")." + this->asMethodFunc()->name();
}
//.........这里部分代码省略.........
示例13: if
void FILEFile::init()
{
// Open mode for file's open
const char *omode = "rb";
if (OpenFlags & Open_Truncate)
{
if (OpenFlags & Open_Read)
omode = "w+b";
else
omode = "wb";
}
else if (OpenFlags & Open_Create)
{
if (OpenFlags & Open_Read)
omode = "a+b";
else
omode = "ab";
}
else if (OpenFlags & Open_Write)
omode = "r+b";
#if defined(OVR_OS_MS)
SysErrorModeDisabler disabler(FileName.ToCStr());
#endif
#if defined(OVR_CC_MSVC) && (OVR_CC_MSVC >= 1400)
wchar_t womode[16];
wchar_t *pwFileName = (wchar_t*)OVR_ALLOC((UTF8Util::GetLength(FileName.ToCStr())+1) * sizeof(wchar_t));
UTF8Util::DecodeString(pwFileName, FileName.ToCStr());
OVR_ASSERT(strlen(omode) < sizeof(womode)/sizeof(womode[0]));
UTF8Util::DecodeString(womode, omode);
fs = _wfsopen(pwFileName, womode, _SH_DENYWR); // Allow others to read the file when we are writing it.
OVR_FREE(pwFileName);
#else
fs = fopen(FileName.ToCStr(), omode);
#endif
if (fs)
rewind (fs);
Opened = (fs != NULL);
// Set error code
if (!Opened)
ErrorCode = SFerror();
else
{
// If we are testing file seek correctness, pre-load the entire file so
// that we can do comparison tests later.
#ifdef OVR_FILE_VERIFY_SEEK_ERRORS
TestPos = 0;
fseek(fs, 0, SEEK_END);
FileTestLength = ftell(fs);
fseek(fs, 0, SEEK_SET);
pFileTestBuffer = (uint8_t*)OVR_ALLOC(FileTestLength);
if (pFileTestBuffer)
{
OVR_ASSERT(FileTestLength == (unsigned)Read(pFileTestBuffer, FileTestLength));
Seek(0, Seek_Set);
}
#endif
ErrorCode = 0;
}
LastOp = 0;
}
示例14: run_helper
void run_helper (const String &uuid, const String &config, const String &display)
{
SCIM_DEBUG_MAIN(1) << "run_helper (" << uuid << "," << config << "," << display << ")\n";
for (size_t i = 0; i < __helpers.size (); ++i) {
if (__helpers [i].first.uuid == uuid && __helpers [i].second.length ()) {
int pid;
pid = fork ();
if (pid < 0) return;
if (pid == 0) {
char * argv [] = { const_cast<char*> (SCIM_HELPER_LAUNCHER_PROGRAM),
const_cast<char*> ("--daemon"),
const_cast<char*> ("--config"), const_cast<char*> (config.c_str ()),
const_cast<char*> ("--display"), const_cast<char*> (display.c_str ()),
const_cast<char*> (__helpers [i].second.c_str ()),
const_cast<char*> (__helpers [i].first.uuid.c_str ()),
0};
SCIM_DEBUG_MAIN(2) << " Call scim-helper-launcher.\n";
execv (SCIM_HELPER_LAUNCHER_PROGRAM, argv);
exit (-1);
}
int status;
waitpid (pid, &status, 0);
break;
}
}
SCIM_DEBUG_MAIN(2) << " exit run_helper ().\n";
}
示例15: shouldExecuteAsJavaScript
bool ScriptElementData::shouldExecuteAsJavaScript() const
{
/*
Mozilla 1.8 accepts javascript1.0 - javascript1.7, but WinIE 7 accepts only javascript1.1 - javascript1.3.
Mozilla 1.8 and WinIE 7 both accept javascript and livescript.
WinIE 7 accepts ecmascript and jscript, but Mozilla 1.8 doesn't.
Neither Mozilla 1.8 nor WinIE 7 accept leading or trailing whitespace.
We want to accept all the values that either of these browsers accept, but not other values.
*/
String type = m_scriptElement->typeAttributeValue();
if (!type.isEmpty()) {
if (!MIMETypeRegistry::isSupportedJavaScriptMIMEType(type.stripWhiteSpace().lower()))
return false;
} else {
String language = m_scriptElement->languageAttributeValue();
if (!language.isEmpty() && !isSupportedJavaScriptLanguage(language))
return false;
}
// No type or language is specified, so we assume the script to be JavaScript.
// We don't yet support setting event listeners via the 'for' attribute for scripts.
// If there is such an attribute it's likely better to not execute the script than to do so
// immediately and unconditionally.
// FIXME: After <rdar://problem/4471751> / https://bugs.webkit.org/show_bug.cgi?id=16915 are resolved
// and we support the for syntax in script tags, this check can be removed and we should just
// return 'true' here.
String forAttribute = m_scriptElement->forAttributeValue();
String eventAttribute = m_scriptElement->eventAttributeValue();
if (forAttribute.isEmpty() || eventAttribute.isEmpty())
return true;
forAttribute = forAttribute.stripWhiteSpace();
eventAttribute = eventAttribute.stripWhiteSpace();
return equalIgnoringCase(forAttribute, "window") && (equalIgnoringCase(eventAttribute, "onload") || equalIgnoringCase(eventAttribute, "onload()"));
}