本文整理汇总了C++中UT_String::substr方法的典型用法代码示例。如果您正苦于以下问题:C++ UT_String::substr方法的具体用法?C++ UT_String::substr怎么用?C++ UT_String::substr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UT_String
的用法示例。
在下文中一共展示了UT_String::substr方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UT_String_getPropVal
/*!
* Assuming a string of standard abiword properties eg. "fred:nerk; table-width:1.0in; table-height:10.in"
* Return the value of the property sProp or NULL if it is not present.
* This UT_String * should be deleted by the calling programming after it is finished with it.
*/
UT_String UT_String_getPropVal(const UT_String & sPropertyString, const UT_String & sProp)
{
UT_String sWork(sProp);
sWork += ":";
const char * szWork = sWork.c_str();
const char * szProps = sPropertyString.c_str();
const char * szLoc = strstr(szProps,szWork);
if(szLoc == NULL)
{
return UT_String();
}
//
// Look if this is the last property in the string.
//
const char * szDelim = strchr(szLoc,';');
if(szDelim == NULL)
{
//
// Remove trailing spaces
//
UT_sint32 iSLen = strlen(szProps);
while(iSLen > 0 && szProps[iSLen-1] == ' ')
{
iSLen--;
}
//
// Calculate the location of the substring
//
UT_sint32 offset = static_cast<UT_sint32>(reinterpret_cast<size_t>(szLoc) - reinterpret_cast<size_t>(szProps));
offset += strlen(szWork);
return UT_String(sPropertyString.substr(offset,(iSLen - offset)));
}
else
{
szDelim = strchr(szLoc,';');
if(szDelim == NULL)
{
//
// bad property string
//
UT_ASSERT(UT_SHOULD_NOT_HAPPEN);
return UT_String();
}
//
// Remove trailing spaces.
//
while(*szDelim == ';' || *szDelim == ' ')
{
szDelim--;
}
//
// Calculate the location of the substring
//
UT_sint32 offset = static_cast<UT_sint32>(reinterpret_cast<size_t>(szLoc) - reinterpret_cast<size_t>(szProps));
offset += strlen(szWork);
UT_sint32 iLen = static_cast<UT_sint32>(reinterpret_cast<size_t>(szDelim) - reinterpret_cast<size_t>(szProps)) + 1;
return UT_String(sPropertyString.substr(offset,(iLen - offset)));
}
}
示例2: fileTypeChanged
void XAP_UnixDialog_FileOpenSaveAs::fileTypeChanged(GtkWidget * w)
{
if (!m_bSave)
return;
UT_sint32 nFileType = XAP_comboBoxGetActiveInt(GTK_COMBO_BOX(w));
UT_DEBUGMSG(("File type widget is %p filetype number is %d \n",w,nFileType));
// I have no idea for 0, but XAP_DIALOG_FILEOPENSAVEAS_FILE_TYPE_AUTO
// definitely means "skip this"
if((nFileType == 0) || (nFileType == XAP_DIALOG_FILEOPENSAVEAS_FILE_TYPE_AUTO))
{
return;
}
gchar * filename = gtk_file_chooser_get_filename(m_FC);
UT_String sFileName = filename;
FREEP(filename);
UT_String sSuffix = m_szSuffixes[nFileType-1];
sSuffix = sSuffix.substr(1,sSuffix.length()-1);
UT_sint32 i = 0;
bool bFoundComma = false;
for(i=0; i< static_cast<UT_sint32>(sSuffix.length()); i++)
{
if(sSuffix[i] == ';')
{
bFoundComma = true;
break;
}
}
if(bFoundComma)
{
sSuffix = sSuffix.substr(0,i);
}
//
// Hard code a suffix
//
if(strstr(sSuffix.c_str(),"gz") != NULL)
{
sSuffix = ".zabw";
}
bool bFoundSuffix = false;
for(i= sFileName.length()-1; i> 0; i--)
{
if(sFileName[i] == '.')
{
bFoundSuffix = true;
break;
}
}
if(!bFoundSuffix)
{
return;
}
sFileName = sFileName.substr(0,i);
sFileName += sSuffix;
gtk_file_chooser_set_current_name(m_FC, UT_basename(sFileName.c_str()));
}
示例3: UT_String_addPropertyString
/*!
* Assuming a string of standard abiword properties eg. "fred:nerk; table-width:1.0in; table-height:10.in"
* Add aother propety string, updating previously defined properties with
* values in the new string.
*/
void UT_String_addPropertyString(UT_String & sPropertyString, const UT_String & sNewProp)
{
UT_sint32 iSize = static_cast<UT_sint32>(sNewProp.size());
UT_sint32 iBase =0;
UT_String sProp;
UT_String sVal;
UT_String sSubStr;
const char * szWork = NULL;
const char * szLoc = NULL;
while(iBase < iSize)
{
bool bBreakAtEnd = false;
sSubStr = sNewProp.substr(iBase, iSize-iBase);
szWork = sSubStr.c_str();
szLoc = strstr(szWork,":");
if(szLoc)
{
sProp = sNewProp.substr(iBase,szLoc - szWork);
}
else
{
break;
}
iBase += szLoc-szWork+1;
sSubStr = sNewProp.substr(iBase, iSize-iBase);
szWork = sSubStr.c_str();
szLoc = strstr(szWork,";");
if(szLoc)
{
sVal = sNewProp.substr(iBase,szLoc - szWork);
iBase += szLoc-szWork+1;
}
else
{
sVal = sNewProp.substr(iBase,iSize-iBase);
bBreakAtEnd = true;
}
if((sProp.size()>0) && (sVal.size() >0))
{
UT_String_setProperty(sPropertyString,sProp,sVal);
}
else
{
break;
}
if(bBreakAtEnd)
{
break;
}
}
}
示例4: fileTypeForSuffixes
IEFileType IE_Imp::fileTypeForSuffixes(const char * suffixList)
{
IEFileType ieft = IEFT_Unknown;
if (!suffixList)
return ieft;
UT_String utSuffix (suffixList);
const size_t len = strlen(suffixList);
size_t i = 0;
while (true)
{
while (i < len && suffixList[i] != '.')
i++;
// will never have all-space extension
const size_t start = i;
while (i < len && suffixList[i] != ';')
i++;
if (i <= len) {
UT_String suffix (utSuffix.substr(start, i-start).c_str());
UT_DEBUGMSG(("DOM: suffix: %s\n", suffix.c_str()));
ieft = fileTypeForSuffix (suffix.c_str());
if (ieft != IEFT_Unknown || i == len)
return ieft;
i++;
}
}
return ieft;
}
示例5: _splitDirectoryAndFileName
/**
* Takes a string like "./ObjectReplacements/Object 1" and split it into
* subdirectory name ("ObjectReplacements") and file name ("Object 1").
*/
void ODi_Abi_Data::_splitDirectoryAndFileName(const gchar* pHRef, UT_String& dirName, UT_String& fileName) const {
UT_String href;
UT_String str;
int iStart, nChars, i, len;
href = pHRef;
////
// Get the directory name
str = href.substr(0, 2);
if (str == "./") {
iStart = 2;
} else {
iStart = 0;
}
len = href.length();
for (i=iStart, nChars=0; i<len; i++) {
if (href[i] == '/') {
i=len; // exit loop
} else {
nChars++;
}
}
UT_ASSERT (nChars > 0 && nChars < len);
dirName = href.substr(iStart, nChars);
////
// Get the file name
iStart = iStart + nChars + 1;
nChars = len - iStart;
UT_ASSERT (nChars); // The file name must have at least one char.
fileName = href.substr(iStart, nChars);
}
示例6: init
void UT_LocaleInfo::init (const UT_String & locale)
{
if (locale.size () == 0)
return;
size_t dot = 0;
size_t hyphen = 0;
// take both hyphen types into account
hyphen = UT_String_findCh (locale, '_');
if (hyphen == (size_t)-1)
hyphen = UT_String_findCh (locale, '-');
dot = UT_String_findCh (locale, '.');
if (hyphen == (size_t)-1 && dot == (size_t)-1)
{
mLanguage = locale.c_str();
return;
}
if (hyphen != (size_t)-1 && dot != (size_t)-1)
{
if (hyphen < dot)
{
mLanguage = locale.substr (0, hyphen).c_str();
mTerritory = locale.substr (hyphen+1, dot-(hyphen+1)).c_str();
mEncoding = locale.substr (dot+1, locale.size ()-(dot+1)).c_str();
}
else
{
mLanguage = locale.substr (0, dot).c_str();
mEncoding = locale.substr (dot+1, locale.size ()-(dot+1)).c_str();
}
}
else if (dot != (size_t)-1)
{
mLanguage = locale.substr (0, dot).c_str();
mEncoding = locale.substr (dot+1, locale.size ()-(dot+1)).c_str();
}
else if (hyphen != (size_t)-1)
{
mLanguage = locale.substr (0, hyphen).c_str();
mEncoding = locale.substr (hyphen+1, locale.size ()-(hyphen+1)).c_str();
}
}
示例7: loadSpriteSheetNames
void BIN_ProjectLoader::loadSpriteSheetNames( const STD_String &projectFolder, StringPairCol_t &sheetNames )
{
// Todo, remove need for PL_FileSpec here!
PL_FileSpec fileSpec( (projectFolder + "/spriteSheets").c_str() );
for ( PL_FileSpec::iterator i = fileSpec.begin(), iEnd = fileSpec.end() ; i!=iEnd ; ++i )
{
if ( i->GetExtension() == UT_String( "bin" ) )
{
UT_String spriteSheetName = i->GetName( false /* no extension */ );
size_t idx = spriteSheetName.find ( "-" );
if ( idx != STD_String::npos )
{
StringPair_t sheetName;
sheetName.first = spriteSheetName.substr( 0, idx ).utf8();
sheetName.second = spriteSheetName.substr( idx+1 ).utf8();
sheetNames.push_back( sheetName );
}
}
}
}
示例8: GetShortPathName
bool XAP_Win32AppImpl::openURL(const char * szURL)
{
// NOTE: could get finer control over browser window via DDE
// NOTE: may need to fallback to WinExec for old NSCP versions
UT_String sURL = szURL;
// If this is a file:// URL, strip off file:// and make it backslashed
if (sURL.substr(0, 7) == "file://")
{
sURL = sURL.substr(7, sURL.size() - 7);
// View as WebPage likes to throw in an extra /\ just for fun, strip it off
if (sURL.substr(0, 2) == "/\\")
sURL = sURL.substr(2, sURL.size() - 2);
if (sURL.substr(0, 1) == "/")
sURL = sURL.substr(1, sURL.size() - 1);
// Convert all forwardslashes to backslashes
for (unsigned int i=0; i<sURL.length();i++)
if (sURL[i]=='/')
sURL[i]='\\';
// Convert from longpath to 8.3 shortpath, in case of spaces in the path
char* longpath = NULL;
char* shortpath = NULL;
longpath = new char[PATH_MAX];
shortpath = new char[PATH_MAX];
strcpy(longpath, sURL.c_str());
DWORD retval = GetShortPathName(longpath, shortpath, PATH_MAX);
if((retval == 0) || (retval > PATH_MAX))
{
UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
DELETEP(longpath);
DELETEP(shortpath);
return false;
}
sURL = shortpath;
DELETEP(longpath);
DELETEP(shortpath);
}
// Query the registry for the default browser so we can directly invoke it
UT_String sBrowser;
HKEY hKey;
unsigned long lType;
DWORD dwSize;
unsigned char* szValue = NULL;
if (RegOpenKeyEx(HKEY_CLASSES_ROOT, "http\\shell\\open\\command", 0, KEY_READ, &hKey) == ERROR_SUCCESS)
{
if(RegQueryValueEx(hKey, NULL, NULL, &lType, NULL, &dwSize) == ERROR_SUCCESS)
{
szValue = new unsigned char[dwSize + 1];
RegQueryValueEx(hKey, NULL, NULL, &lType, szValue, &dwSize);
sBrowser = (char*) szValue;
DELETEP(szValue);
}
RegCloseKey(hKey);
}
/* Now that we have sBrowser from the registry, we need to parse it out.
* If the first character is a double-quote, everything up to and including
* the next double-quote is the sBrowser command. Everything after the
* double-quote is appended to the parameters.
* If the first character is NOT a double-quote, we assume
* everything up to the first whitespace is the command and anything after
* is appended to the parameters.
*/
int iDelimiter;
if (sBrowser.substr(0, 1) == "\"")
iDelimiter = UT_String_findCh(sBrowser.substr(1, sBrowser.length()-1), '"')+2;
else
iDelimiter = UT_String_findCh(sBrowser.substr(0, sBrowser.length()), ' ');
// Store params into a separate UT_String before we butcher sBrowser
UT_String sParams = sBrowser.substr(iDelimiter+1, sBrowser.length()-iDelimiter+1);
// Cut params off of sBrowser so all we're left with is the broweser path & executable
sBrowser = sBrowser.substr(0, iDelimiter);
// Check for a %1 passed in from the registry. If we find it,
// substitute our URL for %1. Otherwise, just append sURL to params.
const char *pdest = strstr(sParams.c_str(), "%1");
if (pdest != NULL)
{
int i = pdest - sParams.c_str() + 1;
sParams = sParams.substr(0, i-1) + sURL + sParams.substr(i+1, sParams.length()-i+1);
}
else
{
sParams = sParams + " " + sURL;
}
// Win95 doesn't like the Browser command to be quoted, so strip em off.
if (sBrowser.substr(0, 1) == "\"")
sBrowser = sBrowser.substr(1, sBrowser.length() - 1);
if (sBrowser.substr(sBrowser.length()-1, 1) == "\"")
sBrowser = sBrowser.substr(0, sBrowser.length() - 1);
//.........这里部分代码省略.........
示例9: UT_String_removeProperty
/*!
* Assuming a string of standard abiword properties eg. "fred:nerk; table-width:1.0in; table-height:10.in"
* Remove the property sProp and it's value from the string of properties.
*/
void UT_String_removeProperty(UT_String & sPropertyString, const UT_String & sProp)
{
UT_String sWork ( sProp );
sWork += ":";
const char * szWork = sWork.c_str();
const char * szProps = sPropertyString.c_str();
const char * szLoc = strstr(szProps,szWork);
if(szLoc == NULL)
{
//
// Not here, do nothing
return ;
}
//
// Found it, Get left part.
//
UT_sint32 locLeft = static_cast<UT_sint32>(reinterpret_cast<size_t>(szLoc) - reinterpret_cast<size_t>(szProps));
UT_String sLeft;
if(locLeft == 0)
{
sLeft.clear();
}
else
{
sLeft = sPropertyString.substr(0,locLeft);
}
locLeft = static_cast<UT_sint32>(sLeft.size());
if(locLeft > 0)
{
//
// If this element is the last item in the properties there is no "; ".
//
// Remove trailing ';' and ' '
//
locLeft--;
while(locLeft >= 0 && (sLeft[locLeft] == ';' || sLeft[locLeft] == ' '))
{
locLeft--;
}
}
UT_String sNew;
if(locLeft > 0)
{
sNew = sLeft.substr(0,locLeft+1);
}
else
{
sNew.clear();
}
//
// Look for ";" to get right part
//
const char * szDelim = strchr(szLoc,';');
if(szDelim == NULL)
{
//
// No properties after this, just assign and return
//
sPropertyString = sNew;
}
else
{
//
// Just slice off the properties and tack them onto the pre-existing sNew
//
while(*szDelim == ';' || *szDelim == ' ')
{
szDelim++;
}
UT_sint32 offset = static_cast<UT_sint32>(reinterpret_cast<size_t>(szDelim) - reinterpret_cast<size_t>(szProps));
UT_sint32 iLen = sPropertyString.size() - offset;
if(sNew.size() > 0)
{
sNew += "; ";
}
sNew += sPropertyString.substr(offset,iLen);
sPropertyString = sNew;
}
}
示例10: _getTranslationCode
static bool _getTranslationCode (FV_View * pView, UT_String & langCode)
{
XAP_Frame * pFrame = static_cast<XAP_Frame *> (pView->getParentData());
UT_return_val_if_fail(pFrame,false);
bool bRet = false;
pFrame->raise();
XAP_Dialog_Id id = XAP_DIALOG_ID_LANGUAGE;
XAP_DialogFactory * pDialogFactory
= static_cast<XAP_DialogFactory *>(pFrame->getDialogFactory());
XAP_Dialog_Language * pDialog
= static_cast<XAP_Dialog_Language *>(pDialogFactory->requestDialog(id));
UT_return_val_if_fail(pDialog,false);
UT_String code ("en-US");
const gchar ** props_in = NULL;
if (pView->getCharFormat(&props_in))
{
const gchar * xml_code = UT_getAttribute("lang", props_in);
if ( xml_code )
{
code = xml_code ;
if ( code.size() >= 2 )
{
code = code.substr (0, 2);
code += '_';
}
}
pDialog->setLanguageProperty(UT_getAttribute("lang", props_in));
FREEP(props_in);
}
// run the dialog
pDialog->runModal(pFrame);
// extract what they did
bool bOK = (pDialog->getAnswer() == XAP_Dialog_Language::a_OK);
if (bOK)
{
const gchar * s;
if (pDialog->getChangedLangProperty(&s))
{
UT_String changedLang = s;
if (changedLang.size() >= 2)
{
code += changedLang.substr(0, 2);
langCode = code;
bRet = true;
}
}
}
pDialogFactory->releaseDialog(pDialog);
return bRet;
}