当前位置: 首页>>代码示例>>C++>>正文


C++ string::begin方法代码示例

本文整理汇总了C++中std::string::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ string::begin方法的具体用法?C++ string::begin怎么用?C++ string::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::string的用法示例。


在下文中一共展示了string::begin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: StringToBool

bool StringToBool(std::string const& str)
{
    std::string lowerStr = str;
    std::transform(str.begin(), str.end(), lowerStr.begin(), [](char c) { return char(::tolower(c)); });
    return lowerStr == "1" || lowerStr == "true" || lowerStr == "yes";
}
开发者ID:090809,项目名称:TrinityCore,代码行数:6,代码来源:Util.cpp

示例2: regex_grep

inline unsigned int regex_grep(bool (*foo)(const match_results<std::string::const_iterator>&), const std::string& s,
                        const regex& e, 
                        match_flag_type flags = match_default)
{
   return regex_grep(foo, s.begin(), s.end(), e, flags);
}
开发者ID:ngzHappy,项目名称:cpc2,代码行数:6,代码来源:regex_grep.hpp

示例3: remove

 std::string remove(std::string expression, const std::string& toRemove) {
     for (std::string::const_iterator str = toRemove.begin(); str != toRemove.end(); str++) {
         expression.erase(std::remove(expression.begin(), expression.end(), *str), expression.end());
     }
     return expression;
 }
开发者ID:pmarathe25,项目名称:Text,代码行数:6,代码来源:strmanip.cpp

示例4: runtime_error

Time::Time(const std::string& str, const std::string& fmt)
: _msecs(0)
{
  unsigned hours = 0;
  unsigned minutes = 0;
  unsigned seconds = 0;
  unsigned mseconds = 0;
  bool am = true;

  enum {
    state_0,
    state_fmt
  } state = state_0;

  std::string::const_iterator dit = str.begin();
  std::string::const_iterator it;
  for (it = fmt.begin(); it != fmt.end(); ++it)
  {
    char ch = *it;
    switch (state)
    {
      case state_0:
        if (ch == '%')
          state = state_fmt;
        else
        {
          if (dit == str.end() || *dit != ch)
            throw std::runtime_error("string <" + str + "> does not match time format <" + fmt + '>');
          ++dit;
        }
        break;

      case state_fmt:
        switch (ch)
        {
          case 'H':
          case 'I':
            hours = getUnsigned(dit, str.end(), 2);
            break;

          case 'M':
            minutes = getUnsigned(dit, str.end(), 2);
            break;

          case 'S':
            seconds = getUnsigned(dit, str.end(), 2);
            break;

          case 'j':
            if (dit != str.end() && *dit == '.')
              ++dit;
            mseconds = getMilliseconds(dit, str.end());
            break;

          case 'J':
          case 'K':
            if (dit != str.end() && *dit == '.')
            {
              ++dit;
              mseconds = getMilliseconds(dit, str.end());
            }
            break;

          case 'k':
            mseconds = getMilliseconds(dit, str.end());
            break;

          case 'p':
            if (dit == str.end()
              || dit + 1 == str.end()
              || ((*dit != 'A'
                && *dit != 'a'
                && *dit != 'P'
                && *dit != 'p')
              || (*(dit + 1) != 'M'
                &&  *(dit + 1) != 'm')))
            {
                throw std::runtime_error("string <" + str + "> does not match time format <" + fmt + '>');
            }

            am = (*dit == 'A' || *dit == 'a');
            dit += 2;
            break;

          default:
            throw std::runtime_error("invalid time format <" + fmt + '>');
        }

        state = state_0;
        break;
    }
  }

  if (it != fmt.end() || dit != str.end())
    throw std::runtime_error("string <" + str + "> does not match time format <" + fmt + '>');

  set(am ? hours : hours + 12, minutes, seconds, mseconds);
}
开发者ID:AndreasWelchlin,项目名称:cxxtools,代码行数:98,代码来源:time.cpp

示例5: is_number

bool is_number(const std::string& s)
{
    std::string::const_iterator it = s.begin();
    while (it != s.end() && (isdigit(*it))) ++it;
    return !s.empty() && it == s.end();
}
开发者ID:zeriyoshi,项目名称:LunaDLL,代码行数:6,代码来源:GlobalFuncs.cpp

示例6: ToLowerCase

 void Toolbox::ToLowerCase(std::string& s)
 {
   std::transform(s.begin(), s.end(), s.begin(), tolower);
 }
开发者ID:gbanana,项目名称:orthanc,代码行数:4,代码来源:Toolbox.cpp

示例7: decode

entry decode(std::string const& str)
{
	return bdecode(str.begin(), str.end());
}
开发者ID:sudarshan-reddy,项目名称:libtorrent,代码行数:4,代码来源:test_bencoding.cpp

示例8: make_tuple

	// returns protocol, auth, hostname, port, path
	boost::tuple<std::string, std::string, std::string, int, std::string>
		parse_url_components(std::string url, error_code& ec)
	{
		std::string hostname; // hostname only
		std::string auth; // user:pass
		std::string protocol; // http or https for instance
		int port = -1;

		std::string::iterator at;
		std::string::iterator colon;
		std::string::iterator port_pos;

		// PARSE URL
		std::string::iterator start = url.begin();
		// remove white spaces in front of the url
		while (start != url.end() && is_space(*start))
			++start;
		std::string::iterator end
			= std::find(url.begin(), url.end(), ':');
		protocol.assign(start, end);

		if (end == url.end())
		{
			ec = errors::unsupported_url_protocol;
			goto exit;
		}
		++end;
		if (end == url.end() || *end != '/')
		{
			ec = errors::unsupported_url_protocol;
			goto exit;
		}
		++end;
		if (end == url.end() || *end != '/')
		{
			ec = errors::unsupported_url_protocol;
			goto exit;
		}
		++end;
		start = end;

		at = std::find(start, url.end(), '@');
		colon = std::find(start, url.end(), ':');
		end = std::find(start, url.end(), '/');

		if (at != url.end()
			&& colon != url.end()
			&& colon < at
			&& at < end)
		{
			auth.assign(start, at);
			start = at;
			++start;
		}

		// this is for IPv6 addresses
		if (start != url.end() && *start == '[')
		{
			port_pos = std::find(start, url.end(), ']');
			if (port_pos == url.end())
			{
				ec = errors::expected_close_bracket_in_address;
				goto exit;
			}
			port_pos = std::find(port_pos, url.end(), ':');
		}
		else
		{
			port_pos = std::find(start, url.end(), ':');
		}

		if (port_pos < end)
		{
			hostname.assign(start, port_pos);
			++port_pos;
			for (std::string::iterator i = port_pos; i < end; ++i)
			{
				if (is_digit(*i)) continue;
				ec = errors::invalid_port;
				goto exit;
			}
			port = std::atoi(std::string(port_pos, end).c_str());
		}
		else
		{
			hostname.assign(start, end);
		}

		start = end;
exit:
		return boost::make_tuple(protocol, auth, hostname, port
			, std::string(start, url.end()));
	}
开发者ID:caisan,项目名称:libtorrent,代码行数:94,代码来源:parse_url.cpp

示例9: replaceSymbols

/**
 * We don't want to pronounce punctuation
 */
void ALSpeech::replaceSymbols(std::string& text)
{
    replace(text.begin(), text.end(), '_', ' ');
    replace(text.begin(), text.end(), ':', ' ');
    replace(text.begin(), text.end(), '-', ' ');
}
开发者ID:Lrosias,项目名称:nbites,代码行数:9,代码来源:ALSpeech.cpp

示例10:

	/// c'tor
	Parser(std::string input_data) :
		data_(input_data),
		state_(data_.begin()),
		error_state_(data_.begin())
	{}
开发者ID:dondieselkopf,项目名称:tmp-parser,代码行数:6,代码来源:parser.hpp

示例11: Lux_OGL_DrawText

void Lux_OGL_DrawText( std::string text, LuxRect dest_rect, Effects image_effects, bool allow_custom )
{
	//glPushMatrix();
	int32_t z = dest_rect.z/1000;
	glColor4ub(image_effects.colour.r, image_effects.colour.g, image_effects.colour.b, image_effects.colour.a);
	uint16_t x = dest_rect.x;
	std::string::iterator object;
	for ( object = text.begin(); object != text.end(); object++ )
	{
		uint32_t cchar = *object;
		/*
		194-223 2 bytes
		224-239 3 bytes
		240-244 4 bytes
		*/
		if (cchar == '\n' || cchar == '\r')
		{
			dest_rect.y += ( oglGraphics_customtext && allow_custom ? oglGraphics_customtext_height + 2 : 10);
			x = dest_rect.x;
		}
		else if ( cchar <= 32 )
		{
			x += 7;
		}
		else if ( cchar <= 128 )
		{
			if ( oglGraphics_customtext && allow_custom )
			{
				x += Lux_OGL_DrawChar((int32_t)cchar,  x, dest_rect.y, z, image_effects);
			}
			else
			{
				glEnable(GL_TEXTURE_2D);
				glBindTexture(GL_TEXTURE_2D, font[cchar-32]);
				glBegin(GL_QUADS);
					glTexCoord2f( 0.0, 0.0 );
					Lux_OGL_ColouredVertex3(image_effects.colour, image_effects.colour2, image_effects.style, 1, x, dest_rect.y, z);
					glTexCoord2f( 1.0, 0.0 );
					Lux_OGL_ColouredVertex3(image_effects.colour, image_effects.colour2, image_effects.style, 2, x + 8, dest_rect.y, z);
					glTexCoord2f( 1.0, 1.0 );
					Lux_OGL_ColouredVertex3(image_effects.colour, image_effects.colour2, image_effects.style, 3, x + 8, dest_rect.y + 8, z);
					glTexCoord2f( 0.0, 1.0 );
					Lux_OGL_ColouredVertex3(image_effects.colour, image_effects.colour2, image_effects.style, 4, x, dest_rect.y + 8, z );
				glEnd();
				glDisable(GL_TEXTURE_2D);
				x += 7;
			}
		}
		else
		{
			glEnable(GL_TEXTURE_2D);
			glBindTexture(GL_TEXTURE_2D, font['?'-32]);
			glBegin(GL_QUADS);
				glTexCoord2f( 0.0, 0.0 );
				Lux_OGL_ColouredVertex3(image_effects.colour, image_effects.colour2, image_effects.style, 1, x, dest_rect.y, z);
				glTexCoord2f( 1.0, 0.0 );
				Lux_OGL_ColouredVertex3(image_effects.colour, image_effects.colour2, image_effects.style, 2, x + 8, dest_rect.y, z);
				glTexCoord2f( 1.0, 1.0 );
				Lux_OGL_ColouredVertex3(image_effects.colour, image_effects.colour2, image_effects.style, 3, x + 8, dest_rect.y + 8, z);
				glTexCoord2f( 0.0, 1.0 );
				Lux_OGL_ColouredVertex3(image_effects.colour, image_effects.colour2, image_effects.style, 4, x, dest_rect.y + 8, z );
			glEnd();
			glDisable(GL_TEXTURE_2D);
			x += 7;
			if ( cchar < 224 )
				object++;
			else if ( cchar < 240 )
				object +=2;
			else if ( cchar < 245 )
				object +=3;
		}

	}
	glColor4f(1.0,1.0,1.0,1.0);
	//glPopMatrix();
}
开发者ID:lukesalisbury,项目名称:luxengine,代码行数:76,代码来源:graphics_opengl.cpp

示例12: append

void DateTimeFormatter::append(std::string& str, const DateTime& dateTime, const std::string& fmt, int timeZoneDifferential)
{
    std::string::const_iterator it  = fmt.begin();
    std::string::const_iterator end = fmt.end();
    while (it != end)
    {
        if (*it == '%')
        {
            if (++it != end)
            {
                switch (*it)
                {
                case 'w':
                    str.append(DateTimeFormat::WEEKDAY_NAMES[dateTime.dayOfWeek()], 0, 3);
                    break;
                case 'W':
                    str.append(DateTimeFormat::WEEKDAY_NAMES[dateTime.dayOfWeek()]);
                    break;
                case 'b':
                    str.append(DateTimeFormat::MONTH_NAMES[dateTime.month() - 1], 0, 3);
                    break;
                case 'B':
                    str.append(DateTimeFormat::MONTH_NAMES[dateTime.month() - 1]);
                    break;
                case 'd':
                    NumberFormatter::append0(str, dateTime.day(), 2);
                    break;
                case 'e':
                    NumberFormatter::append(str, dateTime.day());
                    break;
                case 'f':
                    NumberFormatter::append(str, dateTime.day(), 2);
                    break;
                case 'm':
                    NumberFormatter::append0(str, dateTime.month(), 2);
                    break;
                case 'n':
                    NumberFormatter::append(str, dateTime.month());
                    break;
                case 'o':
                    NumberFormatter::append(str, dateTime.month(), 2);
                    break;
                case 'y':
                    NumberFormatter::append0(str, dateTime.year() % 100, 2);
                    break;
                case 'Y':
                    NumberFormatter::append0(str, dateTime.year(), 4);
                    break;
                case 'H':
                    NumberFormatter::append0(str, dateTime.hour(), 2);
                    break;
                case 'h':
                    NumberFormatter::append0(str, dateTime.hourAMPM(), 2);
                    break;
                case 'a':
                    str.append(dateTime.isAM() ? "am" : "pm");
                    break;
                case 'A':
                    str.append(dateTime.isAM() ? "AM" : "PM");
                    break;
                case 'M':
                    NumberFormatter::append0(str, dateTime.minute(), 2);
                    break;
                case 'S':
                    NumberFormatter::append0(str, dateTime.second(), 2);
                    break;
                case 's':
                    NumberFormatter::append0(str, dateTime.second(), 2);
                    str += '.';
                    NumberFormatter::append0(str, dateTime.millisecond()*1000 + dateTime.microsecond(), 6);
                    break;
                case 'i':
                    NumberFormatter::append0(str, dateTime.millisecond(), 3);
                    break;
                case 'c':
                    NumberFormatter::append(str, dateTime.millisecond()/100);
                    break;
                case 'F':
                    NumberFormatter::append0(str, dateTime.millisecond()*1000 + dateTime.microsecond(), 6);
                    break;
                case 'z':
                    tzdISO(str, timeZoneDifferential);
                    break;
                case 'Z':
                    tzdRFC(str, timeZoneDifferential);
                    break;
                default:
                    str += *it;
                }
                ++it;
            }
        }
        else str += *it++;
    }
}
开发者ID:as2120,项目名称:ZPoco,代码行数:95,代码来源:DateTimeFormatter.cpp

示例13: binary

 explicit binary(const std::string& s) : std::vector<value_type>(s.begin(), s.end()) {}
开发者ID:ChugR,项目名称:qpid-proton,代码行数:1,代码来源:binary.hpp

示例14: format

  std::string RegexSMatch::format(const std::string& s) const
  {
    enum state_type
    {
      state_0,
      state_esc,
      state_var0,
      state_var1,
      state_1
    } state;

    state = state_0;
    std::string ret;

    for (std::string::const_iterator it = s.begin(); it != s.end(); ++it)
    {
      char ch = *it;

      switch (state)
      {
        case state_0:
          if (ch == '$')
            state = state_var0;
          else if (ch == '\\')
            state = state_esc;
          break;

        case state_esc:
          ret += ch;
          state = state_1;
          break;

        case state_var0:
          if (std::isdigit(ch))
          {
            ret = std::string(s.begin(), it - 1);
            regoff_t s = matchbuf[ch - '0'].rm_so;
            regoff_t e = matchbuf[ch - '0'].rm_eo;
            if (s >= 0 && e >= 0)
              ret.append(str, s, e-s);
            state = state_1;
          }
          else
            state = state_0;
          break;

        case state_1:
          if (ch == '$')
            state = state_var1;
          else if (state == '\\')
            state = state_esc;
          else
            ret += ch;
          break;

        case state_var1:
          if (std::isdigit(ch))
          {
            regoff_t s = matchbuf[ch - '0'].rm_so;
            regoff_t e = matchbuf[ch - '0'].rm_eo;
            if (s >= 0 && e >= 0)
              ret.append(str, s, e-s);
            state = state_1;
          }
          else if (ch == '$')
            ret += '$';
          else
          {
            ret += '$';
            ret += ch;
          }
          break;
      }
    }

    switch (state)
    {
      case state_0:
      case state_var0:
        return s;

      case state_esc:
        return ret + '\\';

      case state_var1:
        return ret + '$';

      case state_1:
        return ret;
    }

    return ret;
  }
开发者ID:gema-arta,项目名称:zim-vendor,代码行数:93,代码来源:regex.cpp

示例15: writeBytes

std::size_t ByteBuffer::writeBytes(const std::string& buffer)
{
    _buffer.reserve(_buffer.size() + buffer.size());
    _buffer.insert(_buffer.end(), buffer.begin(), buffer.end());
    return buffer.size();
}
开发者ID:carlesgutierrez,项目名称:ofxIO,代码行数:6,代码来源:ByteBuffer.cpp


注:本文中的std::string::begin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。