本文整理汇总了C++中CStr::Replace方法的典型用法代码示例。如果您正苦于以下问题:C++ CStr::Replace方法的具体用法?C++ CStr::Replace怎么用?C++ CStr::Replace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CStr
的用法示例。
在下文中一共展示了CStr::Replace方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadFileLines
// Return file contents as an array of lines. Assume file is UTF-8 encoded text.
//
// lines = readFileLines(filename);
// filename: VFS filename (may include path)
CScriptVal JSI_VFS::ReadFileLines(ScriptInterface::CxPrivate* pCxPrivate, std::wstring filename)
{
//
// read file
//
CVFSFile file;
if (file.Load(g_VFS, filename) != PSRETURN_OK)
return JSVAL_NULL;
CStr contents = file.DecodeUTF8(); // assume it's UTF-8
// Fix CRLF line endings. (This function will only ever be used on text files.)
contents.Replace("\r\n", "\n");
//
// split into array of strings (one per line)
//
std::stringstream ss(contents);
JSContext* cx = pCxPrivate->pScriptInterface->GetContext();
JSObject* line_array = JS_NewArrayObject(cx, 0, NULL);
std::string line;
int cur_line = 0;
while (std::getline(ss, line))
{
// Decode each line as UTF-8
JS::RootedValue val(cx);
ScriptInterface::ToJSVal(cx, val.get(), CStr(line).FromUTF8());
JS_SetElement(cx, line_array, cur_line++, val.address());
}
return OBJECT_TO_JSVAL( line_array );
}
示例2: ReadFileLines
// Return file contents as an array of lines. Assume file is UTF-8 encoded text.
//
// lines = readFileLines(filename);
// filename: VFS filename (may include path)
JS::Value JSI_VFS::ReadFileLines(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& filename)
{
JSContext* cx = pCxPrivate->pScriptInterface->GetContext();
JSAutoRequest rq(cx);
//
// read file
//
CVFSFile file;
if (file.Load(g_VFS, filename) != PSRETURN_OK)
return JSVAL_NULL;
CStr contents = file.DecodeUTF8(); // assume it's UTF-8
// Fix CRLF line endings. (This function will only ever be used on text files.)
contents.Replace("\r\n", "\n");
//
// split into array of strings (one per line)
//
std::stringstream ss(contents);
JS::RootedObject line_array(cx, JS_NewArrayObject(cx, JS::HandleValueArray::empty()));
std::string line;
int cur_line = 0;
while (std::getline(ss, line))
{
// Decode each line as UTF-8
JS::RootedValue val(cx);
ScriptInterface::ToJSVal(cx, &val, CStr(line).FromUTF8());
JS_SetElement(cx, line_array, cur_line++, val);
}
return JS::ObjectValue(*line_array);
}
示例3: Reload
virtual void Reload()
{
Unload();
CVFSFile vertexFile;
if (vertexFile.Load(g_VFS, m_VertexFile) != PSRETURN_OK)
return;
CVFSFile fragmentFile;
if (fragmentFile.Load(g_VFS, m_FragmentFile) != PSRETURN_OK)
return;
CPreprocessorWrapper preprocessor;
preprocessor.AddDefines(m_Defines);
#if CONFIG2_GLES
// GLES defines the macro "GL_ES" in its GLSL preprocessor,
// but since we run our own preprocessor first, we need to explicitly
// define it here
preprocessor.AddDefine("GL_ES", "1");
#endif
CStr vertexCode = preprocessor.Preprocess(vertexFile.GetAsString());
CStr fragmentCode = preprocessor.Preprocess(fragmentFile.GetAsString());
#if CONFIG2_GLES
// Ugly hack to replace desktop GLSL 1.10/1.20 with GLSL ES 1.00,
// and also to set default float precision for fragment shaders
vertexCode.Replace("#version 110\n", "#version 100\n");
vertexCode.Replace("#version 110\r\n", "#version 100\n");
vertexCode.Replace("#version 120\n", "#version 100\n");
vertexCode.Replace("#version 120\r\n", "#version 100\n");
fragmentCode.Replace("#version 110\n", "#version 100\nprecision mediump float;\n");
fragmentCode.Replace("#version 110\r\n", "#version 100\nprecision mediump float;\n");
fragmentCode.Replace("#version 120\n", "#version 100\nprecision mediump float;\n");
fragmentCode.Replace("#version 120\r\n", "#version 100\nprecision mediump float;\n");
#endif
if (!Compile(m_VertexShader, m_VertexFile, vertexCode))
return;
if (!Compile(m_FragmentShader, m_FragmentFile, fragmentCode))
return;
if (!Link())
return;
m_IsValid = true;
}
示例4: ReadFile
// Return file contents in a string. Assume file is UTF-8 encoded text.
//
// contents = readFile(filename);
// filename: VFS filename (may include path)
CScriptVal JSI_VFS::ReadFile(ScriptInterface::CxPrivate* pCxPrivate, std::wstring filename)
{
CVFSFile file;
if (file.Load(g_VFS, filename) != PSRETURN_OK)
return JSVAL_NULL;
CStr contents = file.DecodeUTF8(); // assume it's UTF-8
// Fix CRLF line endings. (This function will only ever be used on text files.)
contents.Replace("\r\n", "\n");
// Decode as UTF-8
return ScriptInterface::ToJSVal( pCxPrivate->pScriptInterface->GetContext(), contents.FromUTF8() );
}
示例5:
//------------------------------------------------------------------------------
/// \brief Reads Line 2a. WELLID,NNODES
//------------------------------------------------------------------------------
void ProcessorMNW2::impl::ReadLn2a (std::fstream& a_is,
std::fstream& a_os)
{
std::string line;
std::getline(a_is, line);
a_os << line << "\n";
CStr str = line.c_str();
str.Replace('\'', '\"');
EReadAsciiFile e;
e.UseExceptions();
e.SetLine((LPCTSTR)str);
Mnw2Well w;
e.ReadData(w.m_WELLID);
e.ReadData(w.m_NNODES);
m_wells.push_back(w);
} // ProcessorMNW2::impl::ReadLn2a
示例6: ReadFile
// Return file contents in a string. Assume file is UTF-8 encoded text.
//
// contents = readFile(filename);
// filename: VFS filename (may include path)
JS::Value JSI_VFS::ReadFile(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& filename)
{
JSContext* cx = pCxPrivate->pScriptInterface->GetContext();
JSAutoRequest rq(cx);
CVFSFile file;
if (file.Load(g_VFS, filename) != PSRETURN_OK)
return JS::NullValue();
CStr contents = file.DecodeUTF8(); // assume it's UTF-8
// Fix CRLF line endings. (This function will only ever be used on text files.)
contents.Replace("\r\n", "\n");
// Decode as UTF-8
JS::RootedValue ret(cx);
ScriptInterface::ToJSVal(cx, &ret, contents.FromUTF8());
return ret;
}
示例7: InitInstance
BOOL CMortScriptApp::InitInstance()
{
SetRegistryKey( L"Mort" );
CParseCmdLine myCmdLine;
myCmdLine.ParseCmdLine( m_lpCmdLine );
TCHAR exe[MAX_PATH];
::GetModuleFileName(NULL,exe,MAX_PATH);
ExecuteFileName = exe;
CStr file = myCmdLine.Filename; // m_lpCmdLine;
// file.TrimLeft( '\"' ); file.TrimRight( '\"' );
if ( myCmdLine.RegOnly || file.IsEmpty() )
{
RegisterFileClass();
RegisterFileType( L".jscr", L"JScripts" );
RegisterFileType( L".mscr", L"JScripts" );
if ( !myCmdLine.RegOnly )
{
MessageBox( NULL
, L".jscr and .mscr extensions registered.\nPlease run any .jscr/.mscr file or read the manual.\n\n"
L"(c) Mirko Schenk 2005-2007"
, L"JScripts V" + CStr( VERSION_INFO )
, MB_OK|MB_SETFOREGROUND );
}
}
else
{
if ( file.GetLength() >= 4
/* file.GetLength() >= 8 && file.Right(8).CompareNoCase( L".mortrun" ) == 0
|| file.GetLength() >= 5 && file.Right(5).CompareNoCase( L".mscr" ) == 0 */
)
{
CStr mutexName = file;
mutexName.MakeLower();
#ifdef DESKTOP
// Windows XP doesn't like some path characters in the mutex' name
mutexName.Replace( ':', '_' );
mutexName.Replace( '\\', '/' );
#endif
MutexName = (LPCTSTR)mutexName;
HANDLE mutex = ::CreateMutex(NULL, FALSE, MutexName);
if ( mutex!=NULL )
{
int exists = ::GetLastError();
if ( exists == ERROR_ALREADY_EXISTS)
{
DWORD procId = GetRunningScriptProcId( file );
if ( procId != NULL )
{
/*
CString msg;
msg.Format( L"Process ID: %08x", procId );
MessageBox( NULL, msg, L"Debug", MB_SETFOREGROUND );
*/
FindAppT findApp;
findApp.procId = procId;
findApp.hWnd = NULL;
::EnumWindows( FindApplicationWindowProc, (LPARAM)&findApp );
if ( findApp.hWnd != NULL )
{
// msg.Format( L"Set foreground window: %08x", findApp.hWnd );
// MessageBox( NULL, msg, L"Debug", MB_SETFOREGROUND );
::SetForegroundWindow( findApp.hWnd );
}
}
else
exists = 0;
//MessageBox( NULL, L"Process opened", L"Debug", MB_SETFOREGROUND );
/*
TCHAR procName[256];
::GetModuleFileName((HMODULE)procId,procName,256);
//MessageBox( NULL, procName, L"Debug", MB_SETFOREGROUND );
if ( CString(procName).Right(14).CompareNoCase( L"MortScript.exe" ) == 0 )
{
int aw = MessageBox( NULL
, L"Script seems to be running. Cancel old script?"
, L"Script already running"
, MB_YESNO|MB_SETFOREGROUND
);
if ( aw == IDYES )
{
RegWriteDW( HKEY_CURRENT_USER, L"Software\\JScripts\\Abort", MutexName, 1 );
DWORD exitCode = 0;
SetCursor(LoadStandardCursor(IDC_WAIT));
for ( int i=0; i<=10; i++ )
{
Sleep(1000);
if ( GetExitCodeProcess( hProc, &exitCode ) == FALSE )
{
//MessageBox( NULL, L"GetExitCode failed", L"Debug", MB_SETFOREGROUND );
exitCode = 0;
//.........这里部分代码省略.........
示例8: Xeromyces_ReadObject
void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObject *pParent, const std::vector<std::pair<CStr, CStr> >& NameSubst, boost::unordered_set<VfsPath>& Paths)
{
ENSURE(pParent);
int i;
// Our object we are going to create
IGUIObject *object = NULL;
XMBAttributeList attributes = Element.GetAttributes();
// Well first of all we need to determine the type
CStr type (attributes.GetNamedItem(pFile->GetAttributeID("type")));
if (type.empty())
type = "empty";
// Construct object from specified type
// henceforth, we need to do a rollback before aborting.
// i.e. releasing this object
object = ConstructObject(type);
if (!object)
{
// Report error that object was unsuccessfully loaded
LOGERROR(L"GUI: Unrecognized object type \"%hs\"", type.c_str());
return;
}
// Cache some IDs for element attribute names, to avoid string comparisons
#define ELMT(x) int elmt_##x = pFile->GetElementID(#x)
#define ATTR(x) int attr_##x = pFile->GetAttributeID(#x)
ELMT(object);
ELMT(action);
ELMT(repeat);
ATTR(style);
ATTR(type);
ATTR(name);
ATTR(hotkey);
ATTR(z);
ATTR(on);
ATTR(file);
//
// Read Style and set defaults
//
// If the setting "style" is set, try loading that setting.
//
// Always load default (if it's available) first!
//
CStr argStyle (attributes.GetNamedItem(attr_style));
if (m_Styles.count("default") == 1)
object->LoadStyle(*this, "default");
if (! argStyle.empty())
{
// additional check
if (m_Styles.count(argStyle) == 0)
{
LOGERROR(L"GUI: Trying to use style '%hs' that doesn't exist.", argStyle.c_str());
}
else object->LoadStyle(*this, argStyle);
}
//
// Read Attributes
//
bool NameSet = false;
bool ManuallySetZ = false; // if z has been manually set, this turn true
CStr hotkeyTag;
// Now we can iterate all attributes and store
for (i=0; i<attributes.Count; ++i)
{
XMBAttribute attr = attributes.Item(i);
// If value is "null", then it is equivalent as never being entered
if (CStr(attr.Value) == "null")
continue;
// Ignore "type" and "style", we've already checked it
if (attr.Name == attr_type || attr.Name == attr_style)
continue;
// Also the name needs some special attention
if (attr.Name == attr_name)
{
CStr name (attr.Value);
// Apply the requested substitutions
for (size_t j = 0; j < NameSubst.size(); ++j)
name.Replace(NameSubst[j].first, NameSubst[j].second);
object->SetName(name);
NameSet = true;
continue;
}
//.........这里部分代码省略.........