Example #1
0
/***********************************************************
protect part of the string containing character [
***********************************************************/
void ChatBox::ProtectString(std::string &text)
{
	size_t pos=text.find("[");
	while(pos != std::string::npos)
	{
		if((text.size() > pos+2) && ((text[pos+1] == 'c' && text[pos+2] == 'o') || (text[pos+1] == 'i' && text[pos+2] == 'm')))
			pos=text.find("[", pos+1);	
		else
		{
			text.insert(pos, "\\"	);
			pos=text.find("[", pos+2);	
		}
	}
}
Example #2
0
void SHelper::changeFrameNumber(std::string& res, int frame)
{
	int first = res.find('.', 0);
	if(first < 0) return;
		
	int last = res.rfind('.', res.size());
	if(last < 0) return;
	
	char mid[8];
	sprintf(mid, ".%d.", frame);
	
	res.erase(first, last-first+1);
	res.insert(first, mid);
}
Example #3
0
bool changetoknth(std::string &str, int n, const char *with, bool insert = false, bool nonzero = false)
{
    std::string::size_type s = 0, e = 0;
    if (!findtoknth(str, n, s, e))
        return false;
    if (nonzero && str.substr(s, e-s) == "0")
        return true;                                        // not an error
    if (!insert)
        str.replace(s, e-s, with);
    else
        str.insert(s, with);

    return true;
}
Example #4
0
void SHelper::changeFrameNumberFistDot4Digit(std::string& res, int frame)
{
	int first = res.find('.', 0);
	if(first < 0) return;
	
	char mid[8];
	if(frame<10) sprintf(mid, ".000%d.", frame);
	else if(frame<100) sprintf(mid, ".00%d.", frame);
	else if(frame<1000) sprintf(mid, ".0%d.", frame);
	else sprintf(mid, ".%d.", frame);
	
	res.erase(first, 6);
	res.insert(first, mid);
}
Example #5
0
void StrSearchReplace( std::string &s, const std::string &to_find, const std::string& repl_with )
{
	std::string::size_type location = s.find(to_find);
	if ( location == std::string::npos )
	{
		return;
	}
	while ( location != std::string::npos )
	{
		s.erase(location,to_find.size());
		s.insert(location,repl_with);
		location = s.find(to_find, location);
	}
}
Example #6
0
void TextDiagnostic::expandTabs(std::string &SourceLine,
                                std::string &CaretLine) {
    // Scan the source line, looking for tabs.  If we find any, manually expand
    // them to spaces and update the CaretLine to match.
    for (unsigned i = 0; i != SourceLine.size(); ++i) {
        if (SourceLine[i] != '\t') continue;

        // Replace this tab with at least one space.
        SourceLine[i] = ' ';

        // Compute the number of spaces we need to insert.
        unsigned TabStop = DiagOpts.TabStop;
        assert(0 < TabStop && TabStop <= DiagnosticOptions::MaxTabStop &&
               "Invalid -ftabstop value");
        unsigned NumSpaces = ((i+TabStop)/TabStop * TabStop) - (i+1);
        assert(NumSpaces < TabStop && "Invalid computation of space amt");

        // Insert spaces into the SourceLine.
        SourceLine.insert(i+1, NumSpaces, ' ');

        // Insert spaces or ~'s into CaretLine.
        CaretLine.insert(i+1, NumSpaces, CaretLine[i] == '~' ? '~' : ' ');
    }
}
Example #7
0
bool replace_beginning(std::string &haystack, const std::string &needle, const std::string &newStr)
{
  bool replaced = false;

  // Locate the substring to replace
  size_t pos = haystack.find(needle);
  if(pos == std::string::npos) return false;
  if(pos != 0) return false;

  // Replace by erasing and inserting
  haystack.erase( pos, needle.length() );
  haystack.insert( pos, newStr );

  return true;
}
Example #8
0
static void replaceDefines(const std::string& compileTimeDefines, std::string& out)
{
    // Replace semicolons with '#define ... \n'
    if (compileTimeDefines.size() > 0)
    {
        size_t pos;
        out = compileTimeDefines;
        out.insert(0, "#define ");
        while ((pos = out.find(';')) != std::string::npos)
        {
            out.replace(pos, 1, "\n#define ");
        }
        out += "\n";
    }
}
Example #9
0
	std::error_code validate(std::string& path)
	{
		if (path.empty())
			return std::make_error_code(std::errc::invalid_argument);

		if (path[0] == '/')
			return std::make_error_code(std::errc::invalid_argument);

		path.insert(0, "/");

		if (path[path.size() - 1] == '/')
			path = path.substr(0, path.size() - 1);

		return std::error_code();
	}
Example #10
0
bool changenth(std::string& str, int n, const char* with, bool insert = false, bool nonzero = false)
{
    std::string::size_type s, e;
    if (!findnth(str, n, s, e))
        { return false; }

    if (nonzero && str.substr(s, e - s) == "0")
        { return true; }                                        // not an error
    if (!insert)
        { str.replace(s, e - s, with); }
    else
        { str.insert(s, with); }

    return true;
}
Example #11
0
 void Message::setColor(std::string color)
 {
     color.insert((size_t)0, (size_t)(6 - color.size()), '0');
     int r = 0, g = 0, b = 0;
     
     r = strtol(color.substr(0, 2).c_str(), NULL, 16);
     g = strtol(color.substr(2, 2).c_str(), NULL, 16);        
     b = strtol(color.substr(4, 2).c_str(), NULL, 16);
     
     std::vector<int> v;
     v.push_back(r);
     v.push_back(g);
     v.push_back(b);
     this->setColor(v);
 }
Example #12
0
// remove leading and trailing spaces and tabs (useful for copy/paste)
// also, if no protocol specified, add leading "sip:"
std::string
canonize_uri (std::string uri)
{
  const size_t begin_str = uri.find_first_not_of (" \t");
  if (begin_str == std::string::npos)  // there is no content
    return "";

  const size_t end_str = uri.find_last_not_of (" \t");
  const size_t range = end_str - begin_str + 1;
  uri = uri.substr (begin_str, range);
  const size_t pos = uri.find (":");
  if (pos == std::string::npos)
    uri = uri.insert (0, "sip:");
  return uri;
}
Example #13
0
//------------------------------------------------------------------------------
void BroadcastString(std::string& sStr, int sender)
{
   unsigned int len = sStr.length();
   MPI_Bcast(&len, 1, MPI_UNSIGNED, sender, MPI_COMM_WORLD);
   if (sStr.length() < len ) 
   {
      sStr.insert(sStr.end(),(size_t)(len-sStr.length()), ' ');
   }
   else if (sStr.length() > len ) 
   {
      sStr.erase( len,sStr.length()-len);
   }

   MPI_Bcast(const_cast<char *>(sStr.data()), len, MPI_CHAR, sender, MPI_COMM_WORLD);
}
Example #14
0
bool HTTPClient::GET(const std::string &url, std::string &response, const bool bIgnoreNoDataReturned)
{
	response = "";
	std::vector<unsigned char> vHTTPResponse;
	std::vector<std::string> ExtraHeaders;
	if (!GETBinary(url,ExtraHeaders,vHTTPResponse))
		return false;
	if (!bIgnoreNoDataReturned)
	{
		if (vHTTPResponse.empty())
			return false;
	}
	response.insert( response.begin(), vHTTPResponse.begin(), vHTTPResponse.end() );
	return true;
}
Example #15
0
void regexmanager::quote_and_highlight(std::string& str, const std::string& location) {
	std::vector<regex_t *>& regexes = locations[location].first;

	unsigned int i = 0;
	for (auto regex : regexes) {
		if (!regex)
			continue;
		std::string initial_marker = extract_initial_marker(str);
		regmatch_t pmatch;
		unsigned int offset = 0;
		int err = regexec(regex, str.c_str(), 1, &pmatch, 0);
		while (err == 0) {
			// LOG(LOG_DEBUG, "regexmanager::quote_and_highlight: matched %s rm_so = %u rm_eo = %u", str.c_str() + offset, pmatch.rm_so, pmatch.rm_eo);
			std::string marker = utils::strprintf("<%u>", i);
			str.insert(offset + pmatch.rm_eo, std::string("</>") + initial_marker);
			// LOG(LOG_DEBUG, "after first insert: %s", str.c_str());
			str.insert(offset + pmatch.rm_so, marker);
			// LOG(LOG_DEBUG, "after second insert: %s", str.c_str());
			offset += pmatch.rm_eo + marker.length() + strlen("</>") + initial_marker.length();
			err = regexec(regex, str.c_str() + offset, 1, &pmatch, 0);
		}
		i++;
	}
}
Example #16
0
 void select_node(NodeViewerPort nvp){
   if(seek_port.node_viewer != NULL && seek_port.port_type == NO_PORT){
     seek_port.node_viewer->body.box.bg = {0.0,0.0,0.0,1.0};
     seek_port.node_viewer->body.text = saved_text;
   }
   seek_port = nvp;
   if(seek_port.node_viewer != NULL&& seek_port.port_type == NO_PORT){
     text_changed = false;
     seek_port.node_viewer->body.box.bg = {0.1,0.1,0.1,1.0};
     saved_text = seek_port.node_viewer->body.text;
     curser_pos = saved_text.size();
     saved_text.insert(curser_pos,"|");
     seek_port.node_viewer->body.text = saved_text;
   }
 }
Example #17
0
bool BitmapHandler::loadBmpFile(const std::string &fname, std::string &data)
{
	int size;
	char *rawData = ImageUtils::loadFile (fname.c_str(), &size);
	if (rawData!=NULL)
	{
		data.reserve(size);
		data.insert(0, rawData, size);
	} else
	{
		AMIGO_LOG_W(TAG, "::loadBmpFile() FILED to load '%s'\n", fname.c_str());
		return false;
	}
	return true;
}
Example #18
0
const std::string& LLTextUtil::formatPhoneNumber(const std::string& phone_str)
{
	static const std::string PHONE_SEPARATOR = LLUI::sSettingGroups["config"]->getString("AvalinePhoneSeparator");
	static const S32 PHONE_PART_LEN = 2;

	static std::string formatted_phone_str;
	formatted_phone_str = phone_str;
	S32 separator_pos = (S32)(formatted_phone_str.size()) - PHONE_PART_LEN;
	for (; separator_pos >= PHONE_PART_LEN; separator_pos -= PHONE_PART_LEN)
	{
		formatted_phone_str.insert(separator_pos, PHONE_SEPARATOR);
	}

	return formatted_phone_str;
}
Example #19
0
void FindNReplace(std::string &s, const std::string &oldVal,
                  const std::string &newVal)
{
    for (std::string::iterator cur = s.begin();
         cur <= s.end() - oldVal.size();) {
        if (oldVal == std::string{cur, cur + oldVal.size()}) {
            cur = s.erase(cur, cur + oldVal.size());
            int offset = cur - s.begin();
            s.insert(cur, newVal.begin(), newVal.end());
            cur = s.begin() + offset + newVal.size();
        } else {
            ++cur;
        }
    }
}
Example #20
0
    std::string pathSanityFix(std::string path, std::string file_name) {
      // Unify the delimeters,. maybe sketchy solution but it seems to work
      // on at least win7 + ubuntu. All bets are off for older windows
      std::replace(path.begin(), path.end(), '\\', '/');

      // clean up in case of multiples
      auto contains_end = [&](std::string & in) -> bool {
        size_t size = in.size();
        if (!size) return false;
        char end = in[size - 1];
        return (end == '/' || end == ' ');
      };

      while (contains_end(path)) {
        path.erase(path.size() - 1);
      }

      if (!path.empty()) {
        path.insert(path.end(), '/');
      }

      path.insert(path.size(), file_name);
      return path;
    }
Example #21
0
int Socket::recvFrom(std::string& data, int flags, InetAddress& sinaddr)const
{
    char buf[MAX_RECV_SIZE + 1] = { 0 };

    while(true)
    {
        int len = recvFrom(buf, MAX_RECV_SIZE, flags, sinaddr);
        if(len == -1 || len == 0)
            break;
        data.insert(data.end(), buf, buf + len);
        if(len < MAX_RECV_SIZE)
            break;
    }
    return data.size();
}
Example #22
0
void replace(std::string &str, char* find, char* rep, uint32 limit)
{
	uint32 i=0;
	std::string::size_type pos=0;
	while((pos=str.find(find, pos)) != std::string::npos)
	{
		str.erase(pos, strlen(find));
		str.insert(pos, rep);
		pos+=strlen(rep);

		++i;
		if (limit != 0 && i == limit)
			break;
	}
}
Example #23
0
void
ygt::GenerateInstrumentationToolsN (std::string &string,
                                    size_t      toolsSize)
{
    std::string const searchToken ("INSTRUMENTATION_TOOLS_N");
    size_t tokenBegin = string.find (searchToken);

    while (tokenBegin != std::string::npos)
    {
        string.erase (tokenBegin, searchToken.size ());
        string.insert (tokenBegin, std::to_string (toolsSize));

        tokenBegin = string.find (searchToken);
    }
}
Example #24
0
void RichTextBox::sanitizeText(std::string &text, int escape)
{
    std::string escapeString(escape, '#');
    std::string::size_type start = text.find(escapeString);

    while (start != std::string::npos)
    {
        text.insert(start, "#");

        while (text.size() > start && text.at(start) == '#')
            start++;

        start = text.find(escapeString, start);
    }
}
Example #25
0
  void complete(std::string buffer, unsigned int offset,
                completion_handler_t &&completion_handler) const {
    using std::unique_ptr;
    using std::make_unique;

    swift::CompilerInvocation invocation;
    invocation.setMainExecutablePath(state().swift_path);
    invocation.setModuleName("swift_completion");
    invocation.setImportSearchPaths(import_search_paths);
    invocation.setFrameworkSearchPaths(framework_search_paths);
    buffer.insert(offset, 1, 0);
    auto memory_buffer = llvm::MemoryBuffer::getMemBuffer(buffer);
    invocation.setCodeCompletionPoint(memory_buffer.get(), offset);

    swift::ide::CodeCompletionCache completion_cache;
    swift::ide::CodeCompletionContext completion_context(completion_cache);

    struct FunctionalCodeCompletionConsumer final
        : swift::ide::SimpleCachingCodeCompletionConsumer {
      completion_handler_t &completion_handler;

      FunctionalCodeCompletionConsumer(completion_handler_t &completion_handler)
          : completion_handler(completion_handler) {}

      void handleResults(
          swift::MutableArrayRef<swift::ide::CodeCompletionResult *> results)
          override {
        for (auto result : results) {
          completion_handler(*result);
        }
      }
    };

    unique_ptr<swift::ide::CodeCompletionConsumer> consumer =
        make_unique<FunctionalCodeCompletionConsumer>(completion_handler);

    unique_ptr<swift::CodeCompletionCallbacksFactory>
        completion_callbacks_factory(
            swift::ide::makeCodeCompletionCallbacksFactory(completion_context,
                                                           *consumer.get()));

    invocation.setCodeCompletionFactory(completion_callbacks_factory.get());

    swift::CompilerInstance compiler_instance;
    if (!compiler_instance.setup(invocation)) {
      compiler_instance.performSema();
    }
  }
std::string prepare_input(std::string &input, Case const case_mode,
                     Space const space_mode, size_t const word_size)
{
    assert(((space_mode == Space::word_size) ? word_size != 0 : true) &&
           "prepare_input: word_size can't be set as zero");

    std::array<std::array<std::string, 2>, 6> const toChange = {
        {
            {"[éêèëÉÈÊË]", "E"},
            {"[àâÀÂ]",     "A"},
            {"[ûùÛÙ]",     "U"},
            {"[çÇ]",       "C"},
            {"[œŒ]",       "OE"},
            {"[^A-Za-z ]", ""}
        }
    };

    std::regex rgx;
    rgx.imbue(std::locale("fr_FR.UTF8"));
    for (auto const &i: toChange)
    {
        rgx = i[0];
        input = std::regex_replace(input, rgx, i[1]);
    }
    
    if (case_mode == Case::upper)
        for (auto &c: input) c = toupper(c);
    else // case_mode == Case::lower
        for (auto &c: input) c = tolower(c);

    if (space_mode == Space::keep)
        return input;
    else
    {
        input.erase(std::remove(input.begin(), input.end(), ' '), input.end());

        if (space_mode == Space::word_size)
        {
            for (size_t i = word_size; i < input.length(); i += word_size + 1)
            {
                input.insert(input.begin() + i, ' ');
            }

        }

        return input;
    }
}
// Remove all non-cxy items.
Sti_t erase_second_most_nested_scope(std::string &content)
{
    std::pair<Sti_t, Sti_t> most_nested = get_second_most_nested_position(content);
//    std::cout << "POSITIONS:(" << most_nested.first << ", " << most_nested.second << ")\n";
    if (most_nested.first > most_nested.second)
        throw std::invalid_argument("The most nested first comes AFTER second!!!\n");

    // If it's nested
    if (most_nested.second != std::string::npos)
        most_nested.first += sizeof("#cxy starx");
    else
    {
        most_nested.first = 0;
    }

//    std::cout << "Before Operate: " << content;

    std::string to_operate = content.substr(most_nested.first, most_nested.second - most_nested.first);

    std::string all_cxys;
//    std::cout << "To Operate: " << to_operate;

//    Sti_t starx = to_operate.find("#cxy star");
//    Sti_t starx = most_nested.first - sizeof("#cxy starx");
    Sti_t starx = to_operate.find("#cxy star");
    Sti_t stox = get_closing_stop(to_operate, starx);

    while (starx != stox && starx != std::string::npos && stox != std::string::npos)
    {
        all_cxys.append(to_operate.substr(starx, stox - starx + sizeof("#cxy stox")));
//        std::cout << "Cxys: " << to_operate.substr(starx, stox - starx + sizeof("#cxy stox")) << "===============================================\n\n";
        to_operate.erase(starx, stox - starx + sizeof("#cxy stox"));
//        std::cout << "TO OP: " << to_operate << "===============================================\n\n";

        starx = to_operate.find("#cxy star");
        stox = get_closing_stop(to_operate, starx);
    }

    content.erase(most_nested.first, most_nested.second - most_nested.first);

//    std::cout << "Generated content1: " << content;

    content.insert(most_nested.first, all_cxys);

//    std::cout << "Generated content3: " << content;

    return most_nested.first;
}
Example #28
0
void replacestr(std::string &s, std::string const &oldVal, std::string const newVal)
{
    for (std::string::const_iterator it = s.begin(); it < s.end(); ++it) {
        std::string::const_iterator oit = oldVal.begin();
        while (*it == *oit) {
            it++;
            oit++;
            if (it == s.end() || oit == oldVal.end())
                break;
        }
        if (oit == oldVal.end()) {
            it = s.erase(it-oldVal.size(), it);
            it = s.insert(it, newVal.begin(), newVal.end());
        }
    }
}
Example #29
0
void VBOX_BASE::sanitize_format(std::string& output) {
    // Check for special characters used by printf and render them harmless
    string::iterator iter = output.begin();
    while (iter != output.end()) {
        if (*iter == '%') {
            // If we find '%', insert an additional '%' so that the we end up with
            // "%%" in its place.  This with cause printf() type functions to print
            // % within the formatted output.
            //
            iter = output.insert(iter+1, '%');
            ++iter;
        } else {
            ++iter;
        }
    }
}
bool ChangeTokNth(std::string& str, uint32 n, char const* with, bool insert = false, bool allowZero = false)
{
    std::string::size_type s = 0, e = 0;
    if (!FindTokNth(str, n, s, e))
        return false;

    if (allowZero && str.substr(s, e - s) == "0")
        return true;                                        // not an error

    if (!insert)
        str.replace(s, e-s, with);
    else
        str.insert(s, with);

    return true;
}