本文整理汇总了C++中StripSpaces函数的典型用法代码示例。如果您正苦于以下问题:C++ StripSpaces函数的具体用法?C++ StripSpaces怎么用?C++ StripSpaces使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了StripSpaces函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ParseLine
// Ugh, this is ugly.
static bool ParseLine(const std::string& line, std::string* keyOut, std::string* valueOut, std::string* commentOut)
{
int FirstEquals = (int)line.find("=", 0);
int FirstCommentChar = -1;
// Comments
if (FirstCommentChar < 0)
FirstCommentChar =
(int)line.find("#", FirstEquals > 0 ? FirstEquals : 0);
if (FirstCommentChar < 0 && line[0] == ';')
FirstCommentChar = 0;
// Allow preservation of spacing before comment
while (FirstCommentChar > 0 && line[FirstCommentChar - 1] <= ' ')
{
FirstCommentChar--;
}
if ((FirstEquals >= 0) && ((FirstCommentChar < 0) || (FirstEquals < FirstCommentChar)))
{
// Yes, a valid key/value line!
*keyOut = StripSpaces(line.substr(0, FirstEquals));
if (commentOut) *commentOut = FirstCommentChar > 0 ? line.substr(FirstCommentChar) : std::string("");
if (valueOut) *valueOut = StripQuotes(StripSpaces(line.substr(FirstEquals + 1, FirstCommentChar - FirstEquals - 1)));
return true;
}
return false;
}
示例2: GetSection
// Return a list of all lines in a section
bool IniFile::GetLines(const char* sectionName, std::vector<std::string>& lines, const bool remove_comments) const
{
const Section* section = GetSection(sectionName);
if (!section)
return false;
lines.clear();
for (std::vector<std::string>::const_iterator iter = section->lines.begin(); iter != section->lines.end(); ++iter)
{
std::string line = StripSpaces(*iter);
if (remove_comments)
{
int commentPos = (int)line.find('#');
if (commentPos == 0)
{
continue;
}
if (commentPos != (int)std::string::npos)
{
line = StripSpaces(line.substr(0, commentPos));
}
}
lines.push_back(line);
}
return true;
}
示例3: ParseLine
static void
ParseLine(char *line,char *var, char *data)
/*
** This routine divides the line into two parts. The variable, and
** the 'string'. If the line is a comment, the 'data' variable will
** contain the line and 'var' will be empty.
*/
{char *str;
StripSpaces(line);
*data='\0';
*var='\0';
if ((line[0]==';') || (line[0]=='%') || (line[0]=='#'))
{
strcpy(data,line);
return;
}
strcpy(var,line);
str=strpbrk(var," =\t");
if (str!=NULL)
{
strcpy(data,str);
*str='\0';
if ((*data==' ') || (*data=='\t')) StripSpaces(data);
if (*data=='=') {*data=' ';StripSpaces(data);}
}
}
示例4: GetSection
// Return a list of all lines in a section
bool IniFile::GetLines(const std::string& sectionName, std::vector<std::string>* lines, const bool remove_comments) const
{
const Section* section = GetSection(sectionName);
if (!section)
return false;
lines->clear();
for (std::string line : section->lines)
{
line = StripSpaces(line);
if (remove_comments)
{
size_t commentPos = line.find('#');
if (commentPos == 0)
{
continue;
}
if (commentPos != std::string::npos)
{
line = StripSpaces(line.substr(0, commentPos));
}
}
lines->push_back(line);
}
return true;
}
示例5: StripSpaces
bool IniFile::Section::GetLines(std::vector<std::string>* lines, const bool remove_comments) const
{
for (const std::string& line : m_lines)
{
std::string stripped_line = StripSpaces(line);
if (remove_comments)
{
size_t commentPos = stripped_line.find('#');
if (commentPos == 0)
{
continue;
}
if (commentPos != std::string::npos)
{
stripped_line = StripSpaces(stripped_line.substr(0, commentPos));
}
}
lines->push_back(std::move(stripped_line));
}
return true;
}
示例6: HELP
void DOS_Shell::CMD_CHOICE(char * args){
HELP("CHOICE");
static char defchoice[3] = {'y','n',0};
char *rem = NULL, *ptr;
bool optN = ScanCMDBool(args,"N");
bool optS = ScanCMDBool(args,"S"); //Case-sensitive matching
ScanCMDBool(args,"T"); //Default Choice after timeout
if (args) {
char *last = strchr(args,0);
StripSpaces(args);
rem = ScanCMDRemain(args);
if (rem && *rem && (tolower(rem[1]) != 'c')) {
WriteOut(MSG_Get("SHELL_ILLEGAL_SWITCH"),rem);
return;
}
if (args == rem) args = strchr(rem,0)+1;
if (rem) rem += 2;
if(rem && rem[0]==':') rem++; /* optional : after /c */
if (args > last) args = NULL;
}
if (!rem || !*rem) rem = defchoice; /* No choices specified use YN */
ptr = rem;
Bit8u c;
if(!optS) while ((c = *ptr)) *ptr++ = (char)toupper(c); /* When in no case-sensitive mode. make everything upcase */
if(args && *args ) {
StripSpaces(args);
size_t argslen = strlen(args);
if(argslen>1 && args[0] == '"' && args[argslen-1] =='"') {
args[argslen-1] = 0; //Remove quotes
args++;
}
WriteOut(args);
}
/* Show question prompt of the form [a,b]? where a b are the choice values */
if (!optN) {
if(args && *args) WriteOut(" ");
WriteOut("[");
size_t len = strlen(rem);
for(size_t t = 1; t < len; t++) {
WriteOut("%c,",rem[t-1]);
}
WriteOut("%c]?",rem[len-1]);
}
Bit16u n=1;
do {
DOS_ReadFile (STDIN,&c,&n);
} while (!c || !(ptr = strchr(rem,(optS?c:toupper(c)))));
c = optS?c:(Bit8u)toupper(c);
DOS_WriteFile (STDOUT,&c, &n);
dos.return_code = (Bit8u)(ptr-rem+1);
}
示例7: WriteOut
void DOS_Shell::CMD_ECHO(char * args){
if (!*args) {
if (echo) { WriteOut(MSG_Get("SHELL_CMD_ECHO_ON"));}
else { WriteOut(MSG_Get("SHELL_CMD_ECHO_OFF"));}
return;
}
char buffer[512];
char* pbuffer = buffer;
safe_strncpy(buffer,args,512);
StripSpaces(pbuffer);
if (strcasecmp(pbuffer,"OFF")==0) {
echo=false;
return;
}
if (strcasecmp(pbuffer,"ON")==0) {
echo=true;
return;
}
if(strcasecmp(pbuffer,"/?")==0) { HELP("ECHO"); }
args++;//skip first character. either a slash or dot or space
size_t len = strlen(args); //TODO check input of else ook nodig is.
if(len && args[len - 1] == '\r') {
LOG(LOG_MISC,LOG_WARN)("Hu ? carriage return already present. Is this possible?");
WriteOut("%s\n",args);
} else WriteOut("%s\r\n",args);
}
示例8: Get
bool IniFile::Section::Get(const char* key, std::vector<std::string>& values)
{
std::string temp;
bool retval = Get(key, &temp, 0);
if (!retval || temp.empty())
{
return false;
}
// ignore starting , if any
size_t subStart = temp.find_first_not_of(",");
size_t subEnd;
// split by ,
while (subStart != std::string::npos) {
// Find next ,
subEnd = temp.find_first_of(",", subStart);
if (subStart != subEnd)
// take from first char until next ,
values.push_back(StripSpaces(temp.substr(subStart, subEnd - subStart)));
// Find the next non , char
subStart = temp.find_first_not_of(",", subEnd);
}
return true;
}
示例9: StripSpaces
bool Toolbox::IsInteger(const std::string& str)
{
std::string s = StripSpaces(str);
if (s.size() == 0)
{
return false;
}
size_t pos = 0;
if (s[0] == '-')
{
if (s.size() == 1)
{
return false;
}
pos = 1;
}
while (pos < s.size())
{
if (!isdigit(s[pos]))
{
return false;
}
pos++;
}
return true;
}
示例10: SimpleParametersCategory
void SimpleParametersCategory(int num_measures, char *llog, statistics stats, FILE **fOut)
{
int i, j;
char lkk1[LONGSTRINGSIZE], lkk2[LONGSTRINGSIZE], lkk3[LONGSTRINGSIZE];
llog[0]=58; /* ':' */
j=1;
for (i = 1; i <= (num_measures); i=i+2) {
ReadSubKey(lkk1, llog, &j, ':', ':', 0);
StripSpaces(lkk1);
ReadSubKey(lkk2, llog, &j, ':', ':', 0);
StripSpaces(lkk2);
sprintf(lkk3, "%s:#%s#:%s:%E:%E:LIN_DOUBLE:OPT", lkk1, lkk1, lkk2, stats.min[i], stats.max[i]);
fprintf(*fOut, "%s\n", lkk3);
}
}
示例11: Get
bool IniFile::Section::Get(const std::string& key, std::vector<std::string>* out) const
{
std::string temp;
bool retval = Get(key, &temp);
if (!retval || temp.empty())
{
return false;
}
// ignore starting comma, if any
size_t subStart = temp.find_first_not_of(",");
// split by comma
while (subStart != std::string::npos)
{
// Find next comma
size_t subEnd = temp.find(',', subStart);
if (subStart != subEnd)
{
// take from first char until next comma
out->push_back(StripSpaces(temp.substr(subStart, subEnd - subStart)));
}
// Find the next non-comma char
subStart = temp.find_first_not_of(",", subEnd);
}
return true;
}
示例12: ParseLine
void IniFile::ParseLine(const std::string& line, std::string* keyOut, std::string* valueOut)
{
if (line[0] == '#')
return;
size_t firstEquals = line.find("=", 0);
if (firstEquals != std::string::npos)
{
// Yes, a valid line!
*keyOut = StripSpaces(line.substr(0, firstEquals));
if (valueOut)
{
*valueOut = StripQuotes(StripSpaces(line.substr(firstEquals + 1, std::string::npos)));
}
}
}
示例13: MEMBERASSERT
//===============================================================================================
// FUNCTION: GetRemaining
// PURPOSE: Return the remaining text.
//
LPSTR CTextLineParser::GetRemaining()
{
MEMBERASSERT();
if (!m_pszNext || !m_pszNext[0])
return NULL;
if (m_cSeperator != ' ')
return StripSpaces(m_pszNext);
return m_pszNext;
}
示例14: StripSpaces
void USBDeviceAddToWhitelistDialog::AddUSBDeviceToWhitelist()
{
const std::string vid_string = StripSpaces(device_vid_textbox->text().toStdString());
const std::string pid_string = StripSpaces(device_pid_textbox->text().toStdString());
if (!IsValidUSBIDString(vid_string))
{
// i18n: Here, VID means Vendor ID (for a USB device).
ModalMessageBox vid_warning_box(this);
vid_warning_box.setIcon(QMessageBox::Warning);
vid_warning_box.setWindowTitle(tr("USB Whitelist Error"));
// i18n: Here, VID means Vendor ID (for a USB device).
vid_warning_box.setText(tr("The entered VID is invalid."));
vid_warning_box.setStandardButtons(QMessageBox::Ok);
vid_warning_box.exec();
return;
}
if (!IsValidUSBIDString(pid_string))
{
// i18n: Here, PID means Product ID (for a USB device).
ModalMessageBox pid_warning_box(this);
pid_warning_box.setIcon(QMessageBox::Warning);
pid_warning_box.setWindowTitle(tr("USB Whitelist Error"));
// i18n: Here, PID means Product ID (for a USB device).
pid_warning_box.setText(tr("The entered PID is invalid."));
pid_warning_box.setStandardButtons(QMessageBox::Ok);
pid_warning_box.exec();
return;
}
const u16 vid = static_cast<u16>(std::stoul(vid_string, nullptr, 16));
const u16 pid = static_cast<u16>(std::stoul(pid_string, nullptr, 16));
if (SConfig::GetInstance().IsUSBDeviceWhitelisted({vid, pid}))
{
ModalMessageBox::critical(this, tr("Error"), tr("This USB device is already whitelisted."));
return;
}
SConfig::GetInstance().m_usb_passthrough_devices.emplace(vid, pid);
SConfig::GetInstance().SaveSettings();
accept();
}
示例15: libevdev_event_code_get_name
std::string evdevDevice::Button::GetName() const
{
// Buttons below 0x100 are mostly keyboard keys, and the names make sense
if (m_code < 0x100)
{
const char* name = libevdev_event_code_get_name(EV_KEY, m_code);
if (name)
return StripSpaces(name);
}
// But controllers use codes above 0x100, and the standard label often doesn't match.
// We are better off with Button 0 and so on.
return "Button " + std::to_string(m_index);
}