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


C++ basic_string::data方法代码示例

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


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

示例1: StringTrimLeftT

void StringTrimLeftT(std::basic_string<CharType> &output)
{
	size_t check = 0;
	size_t length = output.length();
	const CharType *src = output.data();

	for (; check < length; check++)
		if (NOT_SPACE(src[check]))
			break;

	output.erase(0, check);
}
开发者ID:arlen7772gg,项目名称:NIM_Duilib_Framework,代码行数:12,代码来源:string_util.cpp

示例2: logic_error

    std::basic_string<ToChar>
    convert(const std::basic_string<FromChar>& s, Fun fun)
    {
        std::basic_string<ToChar> result;

        mbstate_t state = {0};

        const FromChar* from = s.data();
        const FromChar* from_end = s.data() + s.size();
        // The interface of cvt is not really iterator-like, and it's
        // not possible the tell the required output size without the conversion.
        // All we can is convert data by pieces.
        while(from != from_end) {

            // std::basic_string does not provide non-const pointers to the data,
            // so converting directly into basic_string<char> is not possible.
            ToChar buffer[32];

            ToChar* to_next = buffer;
            // Need variable because boost::bind doesn't work with rvalues.
            ToChar* to_end = buffer + 32;
            std::codecvt_base::result r = 
                fun(state, from, from_end, from, buffer, to_end, to_next);

            if (r == std::codecvt_base::error)
                throw std::logic_error("character conversion failed");
            // 'partial' is not an error, it just means not all source
            // characters were converted. However, we need to check that at
            // least one new target character was produced. If not, it means
            // the source data is incomplete, and since we don't have extra
            // data to add to source, it's error.
            if (to_next == buffer)
                throw std::logic_error("character conversion failed");

            // Add converted characters
            result.append(buffer, to_next);
        }

        return result;
    }
开发者ID:ueverything,项目名称:mmo-resourse,代码行数:40,代码来源:utf.cpp

示例3: if

const std::basic_string<Byte> out(
    const std::basic_string<CharType>& internal_str,
    const std::codecvt<CharType, Byte, mbstate_t>& codecvt)
{
  typedef std::basic_string<CharType> wstring;
  typedef std::basic_string<Byte>     string;
  typedef std::codecvt<CharType, Byte, mbstate_t> codecvt_type;

  string external_str;

  typename wstring::size_type internal_str_size = internal_str.length();
  typename wstring::size_type out_buf_size =
      static_cast<typename wstring::size_type>(codecvt.max_length()) *
          internal_str_size;

#if defined(MA_USE_CXX11_STDLIB_MEMORY)
  std::unique_ptr<Byte[]> out_buf(new Byte[out_buf_size]);
#else
  boost::scoped_array<Byte> out_buf(new Byte[out_buf_size]);
#endif

  const CharType* first_internal = internal_str.data();
  const CharType* last_internal  = first_internal + internal_str_size;
  const CharType* next_internal  = first_internal;

  Byte* first_external = out_buf.get();
  Byte* last_external  = first_external + out_buf_size;
  Byte* next_external  = first_external;

  typename codecvt_type::state_type state(0);

  typename codecvt_type::result r = codecvt.out(state,
      first_internal, last_internal, next_internal,
      first_external, last_external, next_external);

  if (codecvt_type::ok == r)
  {
    external_str.assign(first_external, next_external);
  }
  else if (codecvt_type::noconv == r)
  {
    external_str.assign(reinterpret_cast<const Byte*>(first_internal),
        reinterpret_cast<const Byte*>(last_internal));
  }
  else
  {
    boost::throw_exception(bad_conversion());
  }

  return external_str;
}
开发者ID:3E--,项目名称:asio_samples,代码行数:51,代码来源:codecvt_cast.hpp

示例4: if

const std::basic_string<CharType> in(
    const std::basic_string<Byte>& external_str,
    const std::codecvt<CharType, Byte, mbstate_t>& codecvt)
{
  typedef std::basic_string<CharType> wstring;
  typedef std::basic_string<Byte>     string;
  typedef std::codecvt<CharType, Byte, mbstate_t> codecvt_type;

  typename string::size_type external_str_size = external_str.length();
  const Byte* first_external = external_str.data();
  const Byte* last_external  = first_external + external_str_size;
  const Byte* next_external  = last_external;

  wstring internal_str;

  typename codecvt_type::state_type state(0);
  typename wstring::size_type out_buf_size =
      static_cast<typename wstring::size_type>(
          codecvt.length(state, first_external, last_external,
              internal_str.max_size()));

#if defined(MA_USE_CXX11_STDLIB_MEMORY)
  detail::unique_ptr<CharType[]> out_buf(new CharType[out_buf_size]);
#else
  detail::scoped_array<CharType> out_buf(new CharType[out_buf_size]);
#endif

  CharType* first_internal = out_buf.get();
  CharType* last_internal  = first_internal + out_buf_size;
  CharType* next_internal  = first_internal;

  typename codecvt_type::result r = codecvt.in(state,
      first_external, last_external, next_external,
      first_internal, last_internal, next_internal);

  if (codecvt_type::ok != r)
  {
    boost::throw_exception(bad_conversion());
  }
  else if (codecvt_type::noconv == r)
  {
    internal_str.assign(reinterpret_cast<const CharType*>(first_external),
        reinterpret_cast<const CharType*>(last_external));
  }
  else
  {
    internal_str.assign(first_internal, last_internal);
  }

  return internal_str;
}
开发者ID:CCJY,项目名称:asio_samples,代码行数:51,代码来源:codecvt_cast.hpp

示例5: overflow

 virtual typename base::int_type
     overflow(typename base::int_type ch = base::traits_type::eof())
     {
         if (ch != base::traits_type::eof())
         {
             std::size_t n = str_.size();
             str_.push_back(static_cast<CharT>(ch));
             str_.resize(str_.capacity());
             base::setp(const_cast<CharT*>(str_.data()),
                        const_cast<CharT*>(str_.data() + str_.size()));
             base::pbump(static_cast<int>(n+1));
         }
         return ch;
     }
开发者ID:lichray,项目名称:libcxx,代码行数:14,代码来源:streambuf.pass.cpp

示例6: overflow

 virtual typename base::int_type
     overflow(typename base::int_type __c = base::traits_type::eof())
     {
         if (__c != base::traits_type::eof())
         {
             int n = static_cast<int>(str_.size());
             str_.push_back(static_cast<CharT>(__c));
             str_.resize(str_.capacity());
             base::setp(const_cast<CharT*>(str_.data()),
                        const_cast<CharT*>(str_.data() + str_.size()));
             base::pbump(n+1);
         }
         return __c;
     }
开发者ID:AstroVPK,项目名称:LLVM-4.0.0,代码行数:14,代码来源:write.pass.cpp

示例7: sizeof

utf8string::utf8string(const std::basic_string<CHAR>& strArg) {
	// Currently no check for validity
	std::string target_enc = utf8_encoding + ignore_tag;
	std::string source_enc = get_encoding<CHAR>().c_str();
	iconv_t converter = iconv_open(target_enc.c_str(), source_enc.c_str());
	size_t inSize = (strArg.length() + 1) * sizeof (CHAR);
	size_t outSize = 6 * strArg.length() + 1; // Maximum Possible UTF-8 size
	std::vector<char> outBuf(outSize);
	char* outBufPtr = outBuf.data();
	const char* inBufPtr = reinterpret_cast<const char *>(strArg.data());
	iconv(converter, &inBufPtr, &inSize, &outBufPtr, &outSize);
	iconv_close(converter);

	m_str.assign(outBuf.data());
}
开发者ID:marviktintor,项目名称:GoToFile,代码行数:15,代码来源:utf8string.cpp

示例8: CreateGlobalData

HGLOBAL CreateGlobalData(const std::basic_string<charT>& str)
{
	HGLOBAL data = ::GlobalAlloc(GMEM_MOVEABLE, ((str.size() + 1) * sizeof(charT)));
	if (data) 
	{
		charT* raw_data = static_cast<charT*>(::GlobalLock(data));
		if (!raw_data)
		{
			::GlobalUnlock(data);
			return nullptr;
		}
		memcpy(raw_data, str.data(), str.size() * sizeof(charT));
		raw_data[str.size()] = '\0';
		::GlobalUnlock(data);
	}
	return data;
}
开发者ID:chanchancl,项目名称:YDWE,代码行数:17,代码来源:YDWEHook.cpp

示例9: read

int UsbIo::read( std::basic_string<unsigned char> & from ,int size )
{
    if ( !isOpen() )
    {
        if ( !open() )
            return -1;
    }
    from.resize( size );
    int res = libusb_control_transfer(
                  pd->handle,
                  CONTROL_REQUEST_TYPE_IN,
                  HID_GET_REPORT,
                  0, 0,
                  const_cast<unsigned char *>( from.data() ), from.size(), pd->timeout );
    if ( res < LIBUSB_SUCCESS )
    {
        close();
        return res;
    }
    return res;
}
开发者ID:z80,项目名称:avrusb,代码行数:21,代码来源:usb_io.cpp

示例10: write

int UsbIo::write( const std::basic_string<unsigned char> & to )
{
    if ( !isOpen() )
    {
        if ( !open() )
            return -1;
    }
    int res = libusb_control_transfer(
                  pd->handle,
                  CONTROL_REQUEST_TYPE_OUT,
                  HID_SET_REPORT,
                  0, 0,
                  const_cast<unsigned char *>( to.data() ), to.size(), pd->timeout );
    //return to.size();
    if ( res < LIBUSB_SUCCESS )
    {
        close();
        return res;
    }
    return res;
}
开发者ID:z80,项目名称:avrusb,代码行数:21,代码来源:usb_io.cpp

示例11: StringTrimT

void StringTrimT(std::basic_string<CharType> &output)
{
	if (output.empty())
		return;
	size_t bound1 = 0;
	size_t bound2 = output.length();
	const CharType *src = output.data();

	for (; bound2 > 0; bound2--)
		if (NOT_SPACE(src[bound2-1]))
			break;

	for (; bound1 < bound2; bound1++)
		if (NOT_SPACE(src[bound1]))
			break;

	if (bound1 < bound2) {
		memmove((void *)src,
				src + bound1,
				sizeof(CharType) * (bound2 - bound1));
	}

	output.resize(bound2 - bound1);
}
开发者ID:arlen7772gg,项目名称:NIM_Duilib_Framework,代码行数:24,代码来源:string_util.cpp

示例12:

 basic_string_view (std::basic_string<CharT, Traits, Allocator> const& that) :
   str { that.data() },
   len { that.size() }
 { }
开发者ID:ilsken,项目名称:core,代码行数:4,代码来源:string.hpp

示例13: return_type

std::basic_string<Out>
codecvt(
	std::basic_string<In> const &_string,
	std::locale const &_locale,
	Function const &_function
)
{
	typedef std::basic_string<
		Out
	> return_type;

	typedef fcppt::container::raw_vector<
		Out
	> buffer_type;

	if(
		_string.empty()
	)
		return return_type();

	fcppt::codecvt_type const &conv(
		std::use_facet<
			fcppt::codecvt_type
		>(
			_locale
		)
	);

	buffer_type buf(
		_string.size()
	);

	typedef fcppt::codecvt_type::state_type state_type;

	state_type state;

	std::memset(
		&state,
		0,
		sizeof(state_type)
	);

	Out *to = buf.data();

	for(
		In const *from = _string.data(),
		*from_next = nullptr;
		; // loop forever
		from = from_next
	)
	{
		Out *to_next;

		std::codecvt_base::result const result(
			(
				conv.*_function
			)(
				state,
				from,
				fcppt::container::data_end(
					_string
				),
				from_next,
				to,
				buf.data_end(),
				to_next
			)
		);

		switch(
			result
		)
		{
		case std::codecvt_base::noconv:
			return
				return_type(
					_string.begin(),
					_string.end()
				);
		case std::codecvt_base::error:
			throw fcppt::exception(
				FCPPT_TEXT("codecvt: error!")
			);
		case std::codecvt_base::partial:
			{
				typename buffer_type::difference_type const diff(
					std::distance(
						buf.data(),
						to_next
					)
				);

				buf.resize(
					buf.size() * 2
				);

				to = buf.data() + diff;
			}
			continue;
		case std::codecvt_base::ok:
//.........这里部分代码省略.........
开发者ID:amoylel,项目名称:fcppt,代码行数:101,代码来源:codecvt.hpp

示例14: serialize

 void serialize(output_archive & ar, std::basic_string<Char, CharTraits,
     Allocator> & s, unsigned)
 {
     ar << s.size(); //-V128
     save_binary(ar, s.data(), s.size() * sizeof(Char));
 }
开发者ID:wzugang,项目名称:hpx,代码行数:6,代码来源:string.hpp

示例15: runTest

void BidiTestRunner::runTest(const std::basic_string<UChar>& input, const std::vector<int>& expectedOrder,
    const std::vector<int>& expectedLevels, bidi_test::ParagraphDirection paragraphDirection,
    const std::string& line, size_t lineNumber)
{
    if (!m_skippedCodePoints.empty()) {
        for (size_t i = 0; i < input.size(); i++) {
            if (m_skippedCodePoints.count(input[i])) {
                m_testsSkipped++;
                return;
            }
        }
    }

    m_testsRun++;

    TextRun textRun(input.data(), input.size());
    switch (paragraphDirection) {
    case bidi_test::DirectionAutoLTR:
        textRun.setDirection(determineParagraphDirectionality(textRun));
        break;
    case bidi_test::DirectionLTR:
        textRun.setDirection(LTR);
        break;
    case bidi_test::DirectionRTL:
        textRun.setDirection(RTL);
        break;
    }
    BidiResolver<TextRunIterator, BidiCharacterRun> resolver;
    resolver.setStatus(BidiStatus(textRun.direction(), textRun.directionalOverride()));
    resolver.setPositionIgnoringNestedIsolates(TextRunIterator(&textRun, 0));

    BidiRunList<BidiCharacterRun>& runs = resolver.runs();
    resolver.createBidiRunsForLine(TextRunIterator(&textRun, textRun.length()));

    std::ostringstream errorContext;
    errorContext << ", line " << lineNumber << " \"" << line << "\"";
    errorContext << " context: " << bidi_test::nameFromParagraphDirection(paragraphDirection);

    std::vector<int> actualOrder;
    std::vector<int> actualLevels;
    actualLevels.assign(input.size(), -1);
    BidiCharacterRun* run = runs.firstRun();
    while (run) {
        // Blink's UBA just makes runs, the actual ordering of the display of characters
        // is handled later in our pipeline, so we fake it here:
        bool reversed = run->reversed(false);
        ASSERT(run->stop() >= run->start());
        size_t length = run->stop() - run->start();
        for (size_t i = 0; i < length; i++) {
            int inputIndex = reversed ? run->stop() - i - 1 : run->start() + i;
            if (!isNonRenderedCodePoint(input[inputIndex]))
                actualOrder.push_back(inputIndex);
            // BidiTest.txt gives expected level data in the order of the original input.
            actualLevels[inputIndex] = run->level();
        }
        run = run->next();
    }

    if (expectedOrder.size() != actualOrder.size()) {
        m_ignoredCharFailures++;
        EXPECT_EQ(expectedOrder.size(), actualOrder.size()) << errorContext.str();
    } else if (expectedOrder != actualOrder) {
        m_orderFailures++;
        printf("ORDER %s%s\n", diffString(actualOrder, expectedOrder).c_str(), errorContext.str().c_str());
    }

    if (expectedLevels.size() != actualLevels.size()) {
        m_ignoredCharFailures++;
        EXPECT_EQ(expectedLevels.size(), actualLevels.size()) << errorContext.str();
    } else {
        for (size_t i = 0; i < expectedLevels.size(); i++) {
            // level == -1 means the level should be ignored.
            if (expectedLevels[i] == actualLevels[i] || expectedLevels[i] == -1)
                continue;

            printf("LEVELS %s%s\n", diffString(actualLevels, expectedLevels).c_str(), errorContext.str().c_str());
            m_levelFailures++;
            break;
        }
    }
    runs.deleteRuns();
}
开发者ID:endlessm,项目名称:chromium-browser,代码行数:82,代码来源:BidiResolverTest.cpp


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