Example #1
0
 virtual typename base::int_type
     overflow(typename base::int_type ch = base::traits_type::eof())
     {
         if (ch != base::traits_type::eof())
         {
             int 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(n+1);
         }
         return ch;
     }
 virtual typename base::int_type
     overflow(typename base::int_type __c = base::traits_type::eof())
     {
         if (__c != base::traits_type::eof())
         {
             int n = str_.size();
             str_.push_back(__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;
     }
Example #3
0
    inline void serializeString(SF::Archive & ar, std::basic_string<C,T,A> & s)
    {
        if (ar.isRead())
        {
            boost::uint32_t count = 0;
            ar & count;

            SF::IStream &is = *ar.getIstream();

            s.resize(0);

            std::size_t minSerializedLength = sizeof(C);
            if (ar.verifyAgainstArchiveSize(count*minSerializedLength))
            {
                if (count > s.capacity())
                {
                    s.reserve(count);
                }
            }

            boost::uint32_t charsRemaining = count;
            const boost::uint32_t BufferSize = 512;
            C buffer[BufferSize];
            while (charsRemaining)
            {
                boost::uint32_t charsToRead = RCF_MIN(BufferSize, charsRemaining);
                boost::uint32_t bytesToRead = charsToRead*sizeof(C);

                RCF_VERIFY(
                    is.read( (char *) buffer, bytesToRead) == bytesToRead,
                    RCF::Exception(RCF::_SfError_ReadFailure()))
                    (bytesToRead)(BufferSize)(count);

                s.append(buffer, charsToRead);
                charsRemaining -= charsToRead;
            }
        }
        else if (ar.isWrite())
        {
            boost::uint32_t count = static_cast<boost::uint32_t >(s.length());
            ar & count;
            ar.getOstream()->writeRaw(
                (char *) s.c_str(),
                count*sizeof(C));
        }

    }
Example #4
0
void test_ok(std::string file,std::locale const &l,std::basic_string<Char> cmp=std::basic_string<Char>())
{
    if(cmp.empty())
        cmp=to<Char>(file);
    std::ofstream test("testi.txt");
    test << file;
    test.close();
    typedef std::basic_fstream<Char> stream_type;

    stream_type f1("testi.txt",stream_type::in);
    f1.imbue(l);
    TEST(read_file<Char>(f1) == cmp); 
    f1.close();

    stream_type f2("testo.txt",stream_type::out);
    f2.imbue(l);
    f2 << cmp;
    f2.close();

    std::ifstream testo("testo.txt");
    TEST(read_file<char>(testo) == file);
}
Example #5
0
void test_pos(std::string source,std::basic_string<Char> target,std::string encoding)
{
    using namespace boost::locale::conv;
    boost::locale::generator g;
    std::locale l= encoding == "ISO8859-8" ? g("he_IL."+encoding) : g("en_US."+encoding);
    TEST(to_utf<Char>(source,encoding)==target);
    TEST(to_utf<Char>(source.c_str(),encoding)==target);
    TEST(to_utf<Char>(source.c_str(),source.c_str()+source.size(),encoding)==target);
    
    TEST(to_utf<Char>(source,l)==target);
    TEST(to_utf<Char>(source.c_str(),l)==target);
    TEST(to_utf<Char>(source.c_str(),source.c_str()+source.size(),l)==target);

    TEST(from_utf<Char>(target,encoding)==source);
    TEST(from_utf<Char>(target.c_str(),encoding)==source);
    TEST(from_utf<Char>(target.c_str(),target.c_str()+target.size(),encoding)==source);
    
    TEST(from_utf<Char>(target,l)==source);
    TEST(from_utf<Char>(target.c_str(),l)==source);
    TEST(from_utf<Char>(target.c_str(),target.c_str()+target.size(),l)==source);
}
Example #6
0
 void name(const std::basic_string<Char>& name, const basic_parsing_context<Char>& context)
 {
     do_name(name.c_str(), name.length(), context);
 }
Example #7
0
void unescape_wide_string(
  const std::string &src,
  std::basic_string<unsigned int> &dest)
{
  dest.reserve(src.size()); // about that long, but may be shorter
  
  for(unsigned i=0; i<src.size(); i++)
  {
    unsigned int ch=(unsigned char)src[i];
    
    if(ch=='\\') // escape?
    {
      i++;
      assert(i<src.size()); // backslash can't be last character

      ch=(unsigned char)src[i];
      switch(ch)
      {
      case '\\': dest.push_back(ch); break;
      case 'n': dest.push_back('\n'); break; /* NL (0x0a) */
      case 't': dest.push_back('\t'); break; /* HT (0x09) */
      case 'v': dest.push_back('\v'); break; /* VT (0x0b) */
      case 'b': dest.push_back('\b'); break; /* BS (0x08) */
      case 'r': dest.push_back('\r'); break; /* CR (0x0d) */
      case 'f': dest.push_back('\f'); break; /* FF (0x0c) */
      case 'a': dest.push_back('\a'); break; /* BEL (0x07) */
      case '"': dest.push_back('"'); break;
      case '\'': dest.push_back('\''); break;
      
      case 'u': // universal character
      case 'U': // universal character
        i++;

        {
          std::string hex;
          
          unsigned count=(ch=='u')?4:8;
          hex.reserve(count);

          for(; count!=0 && i<src.size(); i++, count--)
            hex+=src[i];

          // go back
          i--;
        
          unsigned int result;
          sscanf(hex.c_str(), "%x", &result);
          ch=result;
        }
        
        dest.push_back(ch);
        break;

      case 'x': // hex
        i++;

        {
          std::string hex;
          while(i<src.size() && isxdigit(src[i]))
          {
            hex+=src[i];
            i++;
          }
        
          // go back
          i--;

          unsigned int result;
          sscanf(hex.c_str(), "%x", &result);
          ch=result;
        }
        
        dest.push_back(ch);      
        break;
      
      default:
        if(isdigit(ch)) // octal
        {
          std::string octal;
          
          while(i<src.size() && isdigit(src[i]))
          {
            octal+=src[i];
            i++;
          }
          
          // go back
          i--;
          
          unsigned int result;
          sscanf(octal.c_str(), "%o", &result);
          ch=result;
          dest.push_back(ch);
        }
        else
        {
          // Unknown escape sequence.
          // Both GCC and CL turn \% into %.
          dest.push_back(ch);
        }
      }
    }
    else
      dest.push_back(ch);
  }
}
Example #8
0
 set_state_functor<Char> 
 make_set_state(std::basic_string<Char, Traits, Alloc> const& new_state)
 {
     return set_state_functor<Char>(new_state.c_str());
 }
  inline
  time_duration
  str_from_delimited_time_duration(const std::basic_string<char_type>& s)
  {
    unsigned short min=0, sec =0;
    int hour =0; 
    bool is_neg = (s.at(0) == '-');
    boost::int64_t fs=0;
    int pos = 0;
      
    typedef typename std::basic_string<char_type>::traits_type traits_type;
    typedef boost::char_separator<char_type, traits_type> char_separator_type;
    typedef boost::tokenizer<char_separator_type,
                             typename std::basic_string<char_type>::const_iterator,
                             std::basic_string<char_type> > tokenizer;
    typedef typename boost::tokenizer<char_separator_type,
                             typename std::basic_string<char_type>::const_iterator,
                             typename std::basic_string<char_type> >::iterator tokenizer_iterator;
   
    char_type sep_chars[5] = {'-',':',',','.'};
    char_separator_type sep(sep_chars);
    tokenizer tok(s,sep);
    for(tokenizer_iterator beg=tok.begin(); beg!=tok.end();++beg){
      switch(pos) {
      case 0: {
        hour = boost::lexical_cast<int>(*beg);
        break;
      }
      case 1: {
        min = boost::lexical_cast<unsigned short>(*beg);
        break;
      }
      case 2: {
        sec = boost::lexical_cast<unsigned short>(*beg);
        break;
      };
      case 3: {
        int digits = static_cast<int>(beg->length());
        //Works around a bug in MSVC 6 library that does not support
        //operator>> thus meaning lexical_cast will fail to compile.
#if (defined(BOOST_MSVC) && (_MSC_VER < 1300))
        // msvc wouldn't compile 'time_duration::num_fractional_digits()' 
        // (required template argument list) as a workaround a temp 
        // time_duration object was used
        time_duration td(hour,min,sec,fs);
        int precision = td.num_fractional_digits();
        // _atoi64 is an MS specific function
        if(digits >= precision) {
          // drop excess digits
          fs = _atoi64(beg->substr(0, precision).c_str());
        }
        else {
          fs = _atoi64(beg->c_str());
        }
#else
        int precision = time_duration::num_fractional_digits();
        if(digits >= precision) {
          // drop excess digits
          fs = boost::lexical_cast<boost::int64_t>(beg->substr(0, precision));
        }
        else {
          fs = boost::lexical_cast<boost::int64_t>(*beg);
        }
#endif
        if(digits < precision){
          // trailing zeros get dropped from the string, 
          // "1:01:01.1" would yield .000001 instead of .100000
          // the power() compensates for the missing decimal places
          fs *= power(10, precision - digits); 
        }
        
        break;
      }
      default: break;
      }//switch
      pos++;
    }
    if(is_neg) {
      return -time_duration(hour, min, sec, fs);
    }
    else {
      return time_duration(hour, min, sec, fs);
    }
  }
Example #10
0
inline bool operator > (const std::basic_string<typename re_detail::regex_iterator_traits<RandomAccessIterator>::value_type, traits, Allocator>& s,
                 const sub_match<RandomAccessIterator>& m)
{ return s.compare(m.str()) > 0; }
Example #11
0
	template<typename char_t> bool ends_with(const std::basic_string<char_t>& what, const std::basic_string<char_t>& with)
	{
		return !what.empty() && (what.find(with) == what.length()-with.length());
	}
Example #12
0
void test_from_neg(std::basic_string<Char> source,std::string target,std::string encoding)
{
    using namespace boost::locale::conv;
    boost::locale::generator g;
    std::locale l=g("en_US."+encoding);

    TEST(from_utf<Char>(source,encoding)==target);
    TEST(from_utf<Char>(source.c_str(),encoding)==target);
    TEST(from_utf<Char>(source.c_str(),source.c_str()+source.size(),encoding)==target);
    TEST(from_utf<Char>(source,l)==target);
    TEST(from_utf<Char>(source.c_str(),l)==target);
    TEST(from_utf<Char>(source.c_str(),source.c_str()+source.size(),l)==target);

    TESTF(from_utf<Char>(source,encoding,stop));
    TESTF(from_utf<Char>(source.c_str(),encoding,stop));
    TESTF(from_utf<Char>(source.c_str(),source.c_str()+source.size(),encoding,stop));
    TESTF(from_utf<Char>(source,l,stop));
    TESTF(from_utf<Char>(source.c_str(),l,stop));
    TESTF(from_utf<Char>(source.c_str(),source.c_str()+source.size(),l,stop));
}
inline void code_convert(std::basic_string< CharT, SourceTraitsT, SourceAllocatorT > const& str1, std::basic_string< CharT, TargetTraitsT, TargetAllocatorT >& str2, std::locale const& = std::locale())
{
    str2.append(str1.c_str(), str1.size());
}
	void parse(const std::basic_string<wchar_t>& data)
	{
		for (int index = 0; index < data.length(); ++index) 
		{
			wchar_t currentByte = data[index];

			if (currentByte < 32)
				currentCommandString_ << L"<" << static_cast<int>(currentByte) << L">";
			else
				currentCommandString_ << currentByte;

			if (currentByte != 0)
			{
				switch (currentState_)
				{
					case ExpectingNewCommand:
						if (currentByte == 1) 
							currentState_ = ExpectingCommand;					
						//just throw anything else away
						break;
					case ExpectingCommand:
						if (currentByte == 2) 
							currentState_ = ExpectingParameter;
						else
							command_name_ += currentByte;
						break;
					case ExpectingParameter:
						//allocate new parameter
						if (parameters_.size() == 0 || currentByte == 2)
							parameters_.push_back(std::wstring());

						//add the character to end end of the last parameter
						if (currentByte != 2)
						{
							//add the character to end end of the last parameter
							if (currentByte == L'<')
								parameters_.back() += L"&lt;";
							else if (currentByte == L'>')
								parameters_.back() += L"&gt;";
							else if (currentByte == L'\"')
								parameters_.back() += L"&quot;";
							else
								parameters_.back() += currentByte;
						}

						break;
				}
			}
			else
			{
				std::transform(
					command_name_.begin(), command_name_.end(), 
					command_name_.begin(), 
					toupper);

				try
				{
					if (!command_processor_.handle(command_name_, parameters_))
						CASPAR_LOG(error) << "CLK: Unknown command: " << command_name_;
					else
						CASPAR_LOG(debug) << L"CLK: Executed valid command: " 
							<< currentCommandString_.str();
				} 
				catch (...)
				{
					CASPAR_LOG_CURRENT_EXCEPTION();
					CASPAR_LOG(error) << "CLK: Failed to interpret command: " 
						<< currentCommandString_.str();
				}

				reset();
			}
		}
	}
Example #15
0
 uuid operator()(std::basic_string<ch, char_traits, alloc> const& name) const {
     HashAlgo hash;
     hash.process_bytes(namespace_uuid.begin(), namespace_uuid.size());
     process_characters(hash, name.c_str(), name.length());
     return hash_to_uuid(hash);
 }
Example #16
0
		size_t operator()(const std::basic_string<char, Traits, Allocator>& __s) const
		{
			return __stl_hash_string(__s.c_str());
		}
Example #17
0
		/* ----------------------------------------------------------------- */
		int report(HWND owner, const std::basic_string<TCHAR>& message) {
			return DialogBoxParam(GetModuleHandle(NULL), _T("IDD_REPORT"), owner, report_wndproc, (LPARAM)message.c_str());
		}
 inline bool string_generate(OutputIterator& sink
   , std::basic_string<Char, Traits, Allocator> const& str
   , CharEncoding ce, Tag tag)
 {
     return string_generate(sink, str.c_str(), ce, tag);
 }
 inline bool string_generate(OutputIterator& sink
   , std::basic_string<Char, Traits, Allocator> const& str)
 {
     return string_generate(sink, str.c_str());
 }
Example #20
0
 void value(const std::basic_string<Char>& value, const basic_parsing_context<Char>& context) 
 {
     do_string_value(value.c_str(), value.length(), context);
 }
inline void code_convert(std::basic_string< SourceCharT, SourceTraitsT, SourceAllocatorT > const& str1, std::basic_string< TargetCharT, TargetTraitsT, TargetAllocatorT >& str2, std::locale const& loc = std::locale())
{
    aux::code_convert(str1.c_str(), str1.size(), str2, loc);
}
Example #22
0
std::basic_string<typename detail::switch_char<Ch>::type> convert(const std::basic_string<Ch> & src)
{
    return std::basic_string<typename detail::switch_char<Ch>::type>(src.begin(), src.end());
}
Example #23
0
inline bool IUTEST_ATTRIBUTE_UNUSED_ Compare(const ::std::basic_string<Elem, Traits, Ax>& substr
    , const Elem* actual)
{
    return Compare(substr.c_str(), actual);
}
Example #24
0
 void write(const std::basic_string<CharT>& s)
 {
     write(s.c_str(),s.length());
 }
inline void code_convert(const CharT* str1, std::size_t len, std::basic_string< CharT, TargetTraitsT, TargetAllocatorT >& str2, std::locale const& = std::locale())
{
    str2.append(str1, len);
}
Example #26
0
inline boost::log::aux::light_function< void (basic_formatting_ostream< CharT >&, attributes::named_scope::value_type::value_type const&) >
parse_named_scope_format(std::basic_string< CharT, TraitsT, AllocatorT > const& format)
{
    const CharT* p = format.c_str();
    return parse_named_scope_format(p, p + format.size());
}
Example #27
0
void test_comp(std::locale l,std::basic_string<Char> left,std::basic_string<Char> right,int ilevel,int expected)
{
    typedef std::basic_string<Char> string_type;
    boost::locale::collator_base::level_type level = static_cast<boost::locale::collator_base::level_type>(ilevel);
    TEST(boost::locale::comparator<Char>(l,level)(left,right) == (expected < 0));
    if(ilevel==4) {
        std::collate<Char> const &coll=std::use_facet<std::collate<Char> >(l);
        string_type lt=coll.transform(left.c_str(),left.c_str()+left.size());
        string_type rt=coll.transform(right.c_str(),right.c_str()+right.size());
        if(expected < 0)
            TEST(lt<rt);
        else if(expected == 0) {
            TEST(lt==rt);
        }
        else 
            TEST(lt > rt);
        long lh=coll.hash(left.c_str(),left.c_str()+left.size());
        long rh=coll.hash(right.c_str(),right.c_str()+right.size());
        if(expected == 0)
            TEST(lh==rh);
        else
            TEST(lh!=rh);
    }
    boost::locale::collator<Char> const &coll=std::use_facet<boost::locale::collator<Char> >(l);
    string_type lt=coll.transform(level,left.c_str(),left.c_str()+left.size());
    TEST(lt==coll.transform(level,left));
    string_type rt=coll.transform(level,right.c_str(),right.c_str()+right.size());
    TEST(rt==coll.transform(level,right));
    if(expected < 0)
        TEST(lt<rt);
    else if(expected == 0)
        TEST(lt==rt);
    else 
        TEST(lt > rt);
    long lh=coll.hash(level,left.c_str(),left.c_str()+left.size());
    TEST(lh==coll.hash(level,left));
    long rh=coll.hash(level,right.c_str(),right.c_str()+right.size());
    TEST(rh==coll.hash(level,right));
    if(expected == 0)
        TEST(lh==rh);
    else
        TEST(lh!=rh);

}    
 std::basic_string<CharOut>
 utf_to_utf(std::basic_string<CharIn> const &str,method_type how = default_method)
 {
     return utf_to_utf<CharOut,CharIn>(str.c_str(),str.c_str()+str.size(),how);
 }
 void save(const std::basic_string<CharType> &s)
 {
   unsigned int l = static_cast<unsigned int>(s.size());
   save(l);
   save_impl(s.data(),s.size());
 }
Example #30
0
 uuid operator()(std::basic_string<ch, char_traits, alloc> const& s) const {
     return operator()(s.begin(), s.end());
 }