Beispiel #1
0
inline void kbe_split(const std::basic_string<T>& s, T c, std::vector< std::basic_string<T> > &v)
{
    if(s.size() == 0)
        return;

    typename std::basic_string< T >::size_type i = 0;
    typename std::basic_string< T >::size_type j = s.find(c);

    while(j != std::basic_string<T>::npos)
    {
        std::basic_string<T> buf = s.substr(i, j - i);

        if(buf.size() > 0)
            v.push_back(buf);

        i = ++j;
        j = s.find(c, j);
    }

    if(j == std::basic_string<T>::npos)
    {
        std::basic_string<T> buf = s.substr(i, s.length() - i);
        if(buf.size() > 0)
            v.push_back(buf);
    }
}
Beispiel #2
0
ResultList split_by_tokens(const std::basic_string<CharT> &s,
    const std::basic_string<CharT> &tokens, bool keepEmptyParts = true)
{
    if (tokens.length() == 1)
        return split<ResultList>(s, tokens, keepEmptyParts);

    ResultList slist;

    typename std::basic_string<CharT>::size_type start = 0;
    typename std::basic_string<CharT>::size_type pos;

    std::basic_string<CharT> part;

    // If delimiter.empty():
    //   pos = s.find_first_of(delimiter, start);
    // pos will be s.npos.
    while ((pos = s.find_first_of(tokens, start)) != s.npos) { // strtok
        part = s.substr(start, pos - start);

        if (!part.empty() || keepEmptyParts)
            slist.push_back(part);

        start = pos + 1;
    }

    if (start != s.length() || keepEmptyParts)
        slist.push_back(s.substr(start));

    return slist;
}
    std::vector< std::basic_string< CharType > > str_split( std::basic_string< CharType > const & p_str, std::basic_string< CharType > const & p_delims, uint32_t p_maxSplits, bool p_bKeepVoid )
    {
        typedef std::basic_string< CharType > string_t;
        std::vector< string_t > l_arrayReturn;

        if ( ! p_str.empty() && ! p_delims.empty() && p_maxSplits > 0 )
        {
            l_arrayReturn.reserve( p_maxSplits + 1 );
            std::size_t l_numSplits = 0;
            std::size_t	l_pos = 0;
            std::size_t	l_start = 0;

            do
            {
                l_pos = p_str.find_first_of( p_delims, l_start );

                if ( l_pos == l_start )
                {
                    l_start = l_pos + 1;

                    if ( p_bKeepVoid )
                    {
                        l_arrayReturn.push_back( string_t() );
                    }
                }
                else if ( l_pos == string_t::npos || l_numSplits == p_maxSplits )
                {
                    string_t remnants = p_str.substr( l_start );

                    if ( !remnants.empty() || p_bKeepVoid )
                    {
                        l_arrayReturn.push_back( remnants );
                    }

                    return l_arrayReturn;
                }
                else
                {
                    l_arrayReturn.push_back( p_str.substr( l_start, l_pos - l_start ) );
                    l_start = l_pos + 1;
                }

                //l_start = p_str.find_first_not_of( p_delims, l_start );
                ++ l_numSplits;
            }
            while ( l_pos != string_t::npos );
        }

        return l_arrayReturn;
    }
Beispiel #4
0
ResultList split(const std::basic_string<CharT> &s,
    const std::basic_string<CharT> &delimiter, bool keepEmptyParts = true)
{
    ResultList slist;

    // If delimiter.empty():
    //   pos = s.find(delimiter, start);
    // pos will be 0.
    if (delimiter.empty()) {
        slist.push_back(s);
        return slist;
    }


    typename std::basic_string<CharT>::size_type start = 0;
    typename std::basic_string<CharT>::size_type pos;

    std::basic_string<CharT> part;

    if (delimiter.length() == 1) {
        CharT ch = delimiter[0];

        // Hope that:
        //   find(std::basic_string<CharT>, CharT ch)
        // will be faster than:
        //   find(std::basic_string<CharT>, std::basic_string<CharT>)
        while ((pos = s.find(ch, start)) != s.npos) { // Use strchr/wcschr instead?
            part = s.substr(start, pos - start);

            if (!part.empty() || keepEmptyParts)
                slist.push_back(part);

            start = pos + delimiter.length();
        }
    } else {
        while ((pos = s.find(delimiter, start)) != s.npos) { // Use strstr/wcsstr instead?
            part = s.substr(start, pos - start);

            if (!part.empty() || keepEmptyParts)
                slist.push_back(part);

            start = pos + delimiter.length();
        }
    }

    if (start != s.length() || keepEmptyParts)
        slist.push_back(s.substr(start));

    return slist;
}
Beispiel #5
0
sf::Vector2f FeTextPrimative::setString(
			const std::basic_string<sf::Uint32> &t,
			int position )
{
	//
	// Cut string if it is too big to fit our dimension
	//
	int first_char, len, disp_cpos;
	if ( m_wrap ) position = 0;

	fit_string( t, position, first_char, len );
	m_texts[0].setString( t.substr( first_char, len ) );
	disp_cpos = position - first_char;

	if ( m_texts.size() > 1 )
		m_texts.resize( 1 );

	if (( m_wrap ) && ( len < (int)t.size() ))
	{
		//
		// Calculate the number of lines we can fit in our RectShape
		//
		unsigned int spacing = getCharacterSize() * m_texts[0].getScale().y;
		const sf::Font *font = getFont();
		if ( font )
			spacing = font->getLineSpacing( spacing );

		sf::FloatRect rectSize = m_bgRect.getLocalBounds();
		int line_count = rectSize.height / spacing;

		//
		// Create the wrapped lines
		//
		position = len;
		int i=0;
		while (( position < (int)t.size() - 1 ) && ( i < line_count ))
		{
			fit_string( t, position, first_char, len );
			sf::Text new_text( m_texts[0] );
			new_text.setString( t.substr( first_char, len ) );
			position += len;
			m_texts.push_back( new_text );
			i++;
		}
	}

	set_positions(); // we need to set the positions now for findCharacterPos() to work below
	return m_texts[0].findCharacterPos( disp_cpos );
}
Beispiel #6
0
	std::basic_string<CharType> parent_path(const std::basic_string<CharType>& path)
	{	
		auto index = path.size();

		if (index)
		{
			auto str = path.c_str();

			for (--index; index > 0; --index)
			{
				auto c = str[index];
				if (c != '\\' && c != '/')
					break;
			}

			for (--index; index > 0; --index)
			{
				auto c = str[index];
				if (c == '\\' || c == '/')
					break;
			}
		}

		return index ? path.substr(0, index + 1) : std::basic_string<CharType>();
	}
Beispiel #7
0
void benchmarkT(const char *msg1, F1 f1, const char *msg2, F2 f2, const std::basic_string<C>& str, const std::basic_string<C>& key)
{
	Ret r1 = benchmark1(str, key, f1);
	Ret r2 = benchmark1(str, key, f2);
	printf("%25s %16s % 6.2f %16s % 6.2f %5.2f\n", u16tos(key.substr(0, 25)).c_str(), msg1, r1.clk, msg2, r2.clk, r1.clk / r2.clk);
	TEST_EQUAL(r1, r2);
}
Beispiel #8
0
  std::basic_string<Char> PathRemoveFilename(const std::basic_string<Char>& path)
  {
      std::basic_string<Char>::size_type nLastSlash = 0;
      nLastSlash = StringFindLastOf(path, "\\/");
      if(nLastSlash == std::string::npos) return path;

      return path.substr(0, nLastSlash);
  }
Beispiel #9
0
 static inline std::basic_string<_CharT, _Traits, _Alloc> lstrip(
     const std::basic_string<_CharT, _Traits, _Alloc> &a,
     const strip_t stripchars) {
   typedef std::basic_string<_CharT, _Traits, _Alloc> str_t;
   typename str_t::size_type p = a.find_first_not_of(stripchars);
   if (p == str_t::npos) return "";
   return a.substr(p);
 }
Beispiel #10
0
std::vector<std::basic_string<TCHAR>> Split (const std::basic_string<TCHAR> &inString,
                                  const std::basic_string<TCHAR> &separator)
{
   std::vector<std::basic_string<TCHAR>> returnVector;
   std::basic_string<TCHAR>::size_type start = 0;
   std::basic_string<TCHAR>::size_type end = 0;

   while ((end=inString.find (separator, start)) != std::string::npos)
   {
      returnVector.push_back (inString.substr (start, end-start));
      start = end+separator.size();
   }

   returnVector.push_back (inString.substr (start));

   return returnVector;

} 
Beispiel #11
0
 static inline std::basic_string<_CharT, _Traits, _Alloc> lstrip(
     const std::basic_string<_CharT, _Traits, _Alloc> &a) {
   typedef std::basic_string<_CharT, _Traits, _Alloc> str_t;
   typename str_t::size_type p = 0;
   std::locale loc;
   while (p < a.size() && std::isspace(a[p], loc)) p++;
   if (p == a.size()) return "";
   return a.substr(p);
 }
Beispiel #12
0
 static inline std::basic_string<_CharT, _Traits, _Alloc> rstrip(
     const std::basic_string<_CharT, _Traits, _Alloc> &a) {
   typedef std::basic_string<_CharT, _Traits, _Alloc> str_t;
   typename str_t::size_type p = a.size();
   std::locale loc;
   while (p && std::isspace(a[p-1], loc)) p--;
   if (!p) return "";
   return a.substr(0, p);
 }
		explicit node_select_piece(const std::basic_string<char_type>& str)
			: tag(), type(specifier_type::none_), attr()
		{
			auto f1 = std_future::overload(
				[](const std::string& str) { return str.find_first_of("#."); },
				[](const std::wstring& str) { return str.find_first_of(L"#."); }
			);
			const auto split_pos = f1(str);
			if (basic_string<char_type>::npos == split_pos) {
				tag = str;
			}
			else {
				auto is_sharp = std_future::overload(
					[](const char c) { return '#' == c; },
					[](const wchar_t c) { return L'#' == c; }
				);
				tag = str.substr(0, split_pos);
				type = (is_sharp(str[split_pos])) ? specifier_type::id_ : specifier_type::class_;
				attr = str.substr(split_pos + 1);
			}
		}
Beispiel #14
0
 inline bool PathIsAbsolute(const std::basic_string<Char>& path)
 {
     bool r = false;
     if(path.length() >= 3)
     {
         std::basic_string<Char> sSearch = path.substr(1, 2);
         if(StringEquals(sSearch, ":/") || StringEquals(sSearch, ":\\"))
         {
             r = true;
         }
     }
     return r;
 }
Beispiel #15
0
void CursesOut::draw(const Position &pos, const Style &stl, const std::basic_string<char> &text) const {
    if ((int) text.length() > pos.w) {
        auto s = text.substr(0, pos.w);
        mvaddstr(pos.textY, pos.textX, s.c_str());
        return;
    }
    mvaddstr(pos.textY, pos.textX, text.c_str());
    if ((int) text.length() < pos.w) {
        std::basic_string<char> s;
        s.append(pos.w - text.length(), ' ');
        mvaddstr(pos.textY, pos.textX + text.length(), s.c_str());
    }
}
Beispiel #16
0
	int replace(std::basic_string<Ch, Tr, Alloc>& target, 
			const std::basic_string<Ch, Tr, Alloc>& oldStr, 
			const std::basic_string<Ch, Tr, Alloc>& newStr)
	{
		int replaceCount = 0;

		typedef std::basic_string<Ch, Tr, Alloc> str_type;

		str_type::size_type searchPos = 0;
		str_type::size_type findPos = 0;

		str_type result;

		for(;;)
		{
			findPos = StringUtil::find(target, oldStr, searchPos);
			if(str_type::npos == findPos)
			{
				break;
			}

			result += target.substr(searchPos, (findPos - searchPos));
			result += newStr;
			searchPos = findPos + oldStr.length();
			++replaceCount;
		}

		if(searchPos < target.length())
		{
			result += target.substr(searchPos);
		}

		target = result;

		return replaceCount;
	}
Beispiel #17
0
	template<typename char_t> std::basic_string<char_t> trim(const std::basic_string<char_t>& what)
	{
		if ( what.empty() ) return what;

		const char_t whitespace[3] = { char_t(' '), char_t('\t'), 0 };
		size_t left = what.find_first_not_of(whitespace);
		size_t right = what.find_last_not_of(whitespace);

		if ( left == std::basic_string<char_t>::npos )
		{
			return std::basic_string<char_t>();
		}
		else
		{
			return what.substr(left, right-left+1);
		}
	}
Beispiel #18
0
//@todo test
template<typename TARGET, typename charT, typename traits> std::list<TARGET>
stringToList( const std::basic_string<charT, traits> &source,  charT separator )
{
	std::list<TARGET> ret;

	for (
		size_t next = source.find_first_not_of( separator );
		next != std::string::npos;
		next = source.find_first_not_of( separator, next )
	) {
		const size_t start = next;
		next = source.find( separator, start );
		ret.push_back( boost::lexical_cast<TARGET>( source.substr( start, next - start ) ) );
	}

	return ret;
}
Beispiel #19
0
int main(int argc, char * argv[])
{
	if ( argc < 2 )
		return EXIT_FAILURE;

	::libmaus::autoarray::AutoArray<uint8_t> data = ::libmaus::util::GetFileSize::readFile(argv[1]);
	std::basic_string<wchar_t> const s(data.begin(),data.end());
	uint64_t const n = s.size();

	unsigned int const bitwidth = 64;
	typedef ::libmaus::suffixsort::DivSufSort<bitwidth,wchar_t *,wchar_t const *,int64_t *,int64_t const *,4096> sort_type;
	typedef sort_type::saidx_t saidx_t;

	::libmaus::autoarray::AutoArray<saidx_t> SAdiv0(n,false);	

	std::cerr << "Running divsufsort...";
	sort_type::divsufsort ( reinterpret_cast<wchar_t const *>(s.c_str()) , SAdiv0.get() , n );
	std::cerr << "done." << std::endl;

	if ( n < 20 )
		for ( uint64_t r = 0; r < n; ++r )
		{
			std::wcerr << r << "\t" << SAdiv0[r] << "\t" << s.substr(SAdiv0[r]) << std::endl;
		}
	
	std::wstring t = sufToString(SAdiv0,n);
	
	// std::wcerr << t << std::endl;
	
	// return 0;
	
	::libmaus::autoarray::AutoArray < int64_t > ISA = computeISA(SAdiv0,n);

	std::wstring x = sufToString(ISA,n);
	
	// std::wcerr << x << std::endl;

	::libmaus::autoarray::AutoArray<saidx_t> ISAdiv0(n,false);
	sort_type::divsufsort ( reinterpret_cast<wchar_t const *>(x.c_str()) , ISAdiv0.get() , n );
	
	for ( uint64_t i = 0; i < n; ++i )
		assert ( ISAdiv0[i] == ISA[i] );
}
Beispiel #20
0
	template<typename char_t, typename func> void split(const std::basic_string<char_t>& what, char_t on, func f)
	{
		size_t left = 0, right = 0;

		auto insert_fn = [&what, &f](size_t left, size_t right) -> void
		{
			if ( left < right ) f(trim(what.substr(left, right-left)));
		};
	
		for ( ; right<what.length(); right++ )
		{
			if ( what[right] == on )
			{
				insert_fn(left, right);			
				left = right+1;
			}
		}

		insert_fn(left, right);
	}
int StringTokenizeT(const std::basic_string<CharType> &input,
					const std::basic_string<CharType> &delimitor,
					std::list<std::basic_string<CharType> > &output)
{
	size_t token_begin;
	size_t token_end;

	output.clear();

	for (token_begin = token_end = 0; token_end != std::basic_string<CharType>::npos;)
	{
		token_begin = input.find_first_not_of(delimitor, token_begin);
		if (token_begin == std::basic_string<CharType>::npos)
			break;
		token_end = input.find_first_of(delimitor, token_begin + 1);
		output.push_back(input.substr(token_begin, token_end - token_begin));
		token_begin = token_end + 1;
	}

	return static_cast<int>(output.size());
}
Beispiel #22
0
	std::basic_string<char_type> convert ( std::basic_string<char_type> & s )
	{
		return s.substr( 0, s.find( '\r' ) );
	}
const std::string igs::resource::msg_from_err_(
    const std::basic_string<TCHAR> &tit, const DWORD error_message_id,
    const std::basic_string<TCHAR> &file, const std::basic_string<TCHAR> &line,
    const std::basic_string<TCHAR> &funcsig,
    const std::basic_string<TCHAR> &comp_type,
    const std::basic_string<TCHAR> &msc_full_ver,
    const std::basic_string<TCHAR> &date,
    const std::basic_string<TCHAR> &time) {
  /*
汎用データ型  ワイド文字(UNICODE)(※1)	マルチバイト文字(_MBCS)(※2)
TCHAR	      wchar_t			char
LPTSTR	      wchar_t *			char *
LPCTSTR	      const wchar_t *		const char *
※1  1文字を16ビットのワイド文字として表すUnicode を使う方法
  すべての文字が 16 ビットに固定されます。
  マルチバイト文字に比べ、メモリ効率は低下しますが処理速度は向上します
※2  1文字を複数のバイトで表すマルチバイト文字
  MBCS(Multibyte Character Set) と呼ばれる文字集合を使う方法
  可変長だが、事実上、サポートされているのは 2 バイト文字までなので、
  マルチバイト文字の 1 文字は 1 バイトまたは 2 バイトとなります。
  Windows 2000 以降、Windows は内部で Unicode を使用しているため、
  マルチバイト文字を使用すると内部で文字列の変換が発生するため
  オーバーヘッドが発生します。
  UNICODEも_MBCSも未定義のときはこちらになる。
*/
  std::basic_string<TCHAR> errmsg;
  errmsg += TEXT('\"');

  /* makefile-vc2008mdAMD64等でコンパイルすると
  フルパスで入ってくるのでファイル名だけにする
  */
  std::basic_string<TCHAR>::size_type index = file.find_last_of(TEXT("/\\"));
  if (std::basic_string<TCHAR>::npos != index) {
    errmsg += file.substr(index + 1);
  } else {
    errmsg += file;
  }

  errmsg += TEXT(':');
  errmsg += line;
  errmsg += TEXT(':');
  errmsg += comp_type;
  errmsg += TEXT(":");
  errmsg += msc_full_ver;
  {
    std::basic_istringstream<TCHAR> ist(date);
    std::basic_string<TCHAR> month, day, year;
    ist >> month;
    ist >> day;
    ist >> year;
    errmsg += TEXT(':');
    errmsg += year;
    errmsg += TEXT(':');
    errmsg += month;
    errmsg += TEXT(':');
    errmsg += day;
  }
  errmsg += TEXT(':');
  errmsg += time;
  errmsg += TEXT('\"');
  errmsg += TEXT(' ');
  errmsg += TEXT('\"');
  errmsg += funcsig;
  errmsg += TEXT('\"');
  errmsg += TEXT(' ');
  errmsg += TEXT('\"');
  if (0 < tit.size()) {
    errmsg += tit;
  }
  if (NO_ERROR != error_message_id) {
    errmsg += TEXT(':');
    LPTSTR lpMsgBuf = 0;
    if (0 < ::FormatMessage(
                FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
                    FORMAT_MESSAGE_IGNORE_INSERTS,
                NULL, error_message_id,
                MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT) /* 既定言語 */
                ,
                reinterpret_cast<LPTSTR>(&lpMsgBuf), 0,
                NULL)) { /* --- 成功 --- */
      errmsg += lpMsgBuf;
      ::LocalFree(lpMsgBuf);
      std::string::size_type index = errmsg.find_first_of(TEXT("\r\n"));
      if (std::string::npos != index) {
        errmsg.erase(index);
      }
    } else { /* エラー */
      errmsg += TEXT("FormatMessage() can not get (error)message");
    }
  }
  errmsg += TEXT('\"');

  /* MBCSで返す */
  return igs::resource::mbs_from_ts(errmsg);
}
Beispiel #24
0
sf::Vector2f FeTextPrimative::setString(
			const std::basic_string<sf::Uint32> &t,
			int position )
{
	//
	// Cut string if it is too big to fit our dimension
	//
	int first_char, len, disp_cpos;
	std::vector< int > fc_list;
	std::vector< int > len_list;

	if ( m_first_line >= 0 )
		position = 0;

	fit_string( t, position, first_char, len );

	fc_list.push_back( first_char );
	len_list.push_back( len );

	disp_cpos = position - first_char;

	if ( m_texts.size() > 1 )
		m_texts.resize( 1 );

	if (( m_first_line >= 0 ) && ( len < (int)t.size() ))
	{
		//
		// Calculate the number of lines we can fit in our RectShape
		//
		unsigned int spacing = getCharacterSize() * m_texts[0].getScale().y;
		const sf::Font *font = getFont();
		if ( font )
			spacing = font->getLineSpacing( spacing );

		sf::FloatRect rectSize = m_bgRect.getLocalBounds();
		int line_count = rectSize.height / spacing;

		//
		// Calculate the wrapped lines
		//
		position += len;
		int i=0;
		int actual_first_line=0;
		while (( position < (int)t.size() - 1 ) && ( i < line_count + m_first_line ))
		{
			if ( i >= line_count )
				actual_first_line++;

			fit_string( t, position, first_char, len );

			fc_list.push_back( first_char );
			len_list.push_back( len );
			position += len;
			i++;
		}

		m_first_line = actual_first_line;

		int actual_lines = ( (int)fc_list.size() < line_count ) ? fc_list.size() : line_count;
		int first_fc = fc_list.size() - actual_lines;

		//
		// Now create the wrapped lines
		//
		m_texts[0].setString( t.substr( fc_list[first_fc], len_list[first_fc] ) );
		for ( i = first_fc + 1; i < (int)fc_list.size(); i++ )
		{
			m_texts.push_back( m_texts[0] );
			m_texts.back().setString( t.substr( fc_list[i], len_list[i] ) );
		}
	}
	else
		// create the no-wrap or single non-clipped line
		m_texts[0].setString( t.substr( fc_list.front(), len_list.front() ) );

	set_positions(); // we need to set the positions now for findCharacterPos() to work below
	return m_texts[0].findCharacterPos( disp_cpos );
}