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; }
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; }
template<typename char_t> std::basic_string<char_t> strip(const std::basic_string<char_t>& what, const std::basic_string<char_t> of_what) { std::basic_string<char_t> result; for ( size_t i=0; i<what.length(); i++ ) { if ( of_what.find(what[i]) == std::basic_string<char_t>::npos ) { result.push_back(what[i]); } } return result; }
explicit dynamic_bitset(const std::basic_string<CharT, Traits, Alloc>& s, typename std::basic_string<CharT, Traits, Alloc>::size_type pos = 0, typename std::basic_string<CharT, Traits, Alloc>::size_type n = (std::basic_string<CharT, Traits, Alloc>::npos), const Allocator& alloc = Allocator()) : detail::dynamic_bitset_base<Block, Allocator> (std::min(n, s.size() - pos), alloc) #endif { // Locate sub string assert(pos <= s.length()); from_string(s, pos, std::min(n, s.size() - pos)); }
inline typename quan::where_< quan::meta::bool_< (sizeof(CharTo) < sizeof(CharFrom))>, std::basic_string<CharTo> >::type convert(std::basic_string<CharFrom> const & in) { typedef std::ctype<CharFrom> ct; auto & facet = std::use_facet<ct>(std::locale()); std::basic_string<CharTo> result; for ( auto i = 0U ; i < in.length();++i){ result += facet.narrow(in[i],'#'); } return result; }
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; }
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)); } }
inline void serialize(SF::Archive &ar, std::basic_string<C,T,A> &t, const unsigned int) { if (ar.isRead()) { C *pch = NULL; UInt32 length = 0; ar & SF::Archive::Flag( SF::Archive::NO_BEGIN_END ) & dynamicArray(pch, length); t.assign(pch, length); delete [] pch; } else if (ar.isWrite()) { C *pch = const_cast<C *>(t.c_str()); UInt32 length = static_cast<UInt32>(t.length()); ar & SF::Archive::Flag( SF::Archive::NO_BEGIN_END ) & dynamicArray(pch, length); } }
/** Convert a string to a valid symbol. * * This will make a best effort at turning `str` into a complete, valid * Symbol, and will always return one. */ static inline Symbol symbolify(const std::basic_string<char>& in) { if (in.empty()) { return Symbol("_"); } std::basic_string<char> out(in); for (size_t i = 0; i < in.length(); ++i) { if (!is_valid_char(out[i])) { out[i] = '_'; } } if (is_valid_start_char(out[0])) { return Symbol(out); } else { return Symbol(std::string("_") + out); } }
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); }
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); }
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); }
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"<"; else if (currentByte == L'>') parameters_.back() += L">"; else if (currentByte == L'\"') parameters_.back() += L"""; 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(); } } }
template<class Ch> inline bool startsWith(const std::basic_string<Ch>& text, const Ch* prefix, ulong_t startOffset = 0) {return startsWith(text.data() + startOffset, text.length() - startOffset, prefix, -1);}
template<class Ch> inline status_t numericValue(const std::basic_string<Ch>& text, long& result, uint_t base=10) {return numericValue(text.data(), text.data() + text.length(), result, base);}
template<class Ch> inline bool startsWithIgnoreCase(const std::basic_string<Ch>& text, const std::basic_string<Ch>& prefix, ulong_t startOffset = 0) {return startsWithIgnoreCase(text.data() + startOffset, text.length() - startOffset, prefix.data(), prefix.length());}
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()); }
basic_string(const std::basic_string<CharType> & newstr) : buffer(newstr.c_str()), buffer_length(newstr.length()) {}
void write(const std::basic_string<CharT>& s) { write(s.c_str(),s.length()); }
void value(const std::basic_string<Char>& value) { do_string_value(value.c_str(), value.length()); }
uuid operator()(std::basic_string<ch, char_traits, alloc> const& name) { reset(); process_characters(name.c_str(), name.length()); return sha_to_uuid(); }
void name(const std::basic_string<Char>& name) { do_name(name.c_str(), name.length()); }
template<class Ch> inline bool equalsIgnoreCase(const std::basic_string<Ch>& s1, const std::basic_string<Ch>& s2) {return equalsIgnoreCase(s1.data(), s1.data() + s1.length(), s2.data(), s2.data() + s2.length());}
void name(const std::basic_string<Char>& name, const basic_parsing_context<Char>& context) { do_name(name.c_str(), name.length(), context); }
basic_string_ref(const std::basic_string<charT, traits, Allocator>& str) : ptr_(str.data()), len_(str.length()) {}
virtual void parse(const std::basic_string<wchar_t>& data) { auto p = data.c_str(); strategy_->Parse(p, static_cast<int>(data.length()), client_info_); }
void value(const std::basic_string<Char>& value, const basic_parsing_context<Char>& context) { do_string_value(value.c_str(), value.length(), context); }
template<class Ch> inline bool equalsIgnoreCase(const Ch* s2, const std::basic_string<Ch>& s1) {return equalsIgnoreCase(s1.data(), s1.data() + s1.length(), s2, s2 + Len(s2));}