inline basic_cstring<CharT> basic_cstring<CharT>::default_trim_ex() { static CharT ws[3] = { CharT(' '), CharT('\t'), CharT('\n') }; // !! wide case return self_type( ws, 3 ); }
static #endif /* !__SUNPRO_CC */ PRInt32 FindCharInSet( const CharT* data, PRUint32 dataLen, const SetCharT* set ) { CharT filter = nsBufferRoutines<CharT>::get_find_in_set_filter(set); const CharT* end = data + dataLen; for (const CharT* iter = data; iter < end; ++iter) { CharT currentChar = *iter; if (currentChar & filter) continue; // char is not in filter set; go on with next char. // test all chars const SetCharT* charInSet = set; CharT setChar = CharT(*charInSet); while (setChar) { if (setChar == currentChar) return iter - data; // found it! return index of the found char. setChar = CharT(*(++charInSet)); } } return kNotFound; }
inline std::basic_istream<CharT,Traits>& operator>>(std::basic_istream<CharT,Traits>& is, uuid& id) { typedef typename std::basic_istream<CharT,Traits>::sentry sentry_t; sentry_t ok(is); if (ok) { CharT c; if (!is.get(c)) return is; is.unget(); if (c == is.widen('{')) { CharT buf[38+1]; if (!is.read(buf, 38)) return is; buf[38] = CharT(); id = uuid(buf); } else { CharT buf[36+1]; if (!is.read(buf, 36)) return is; buf[36] = CharT(); id = uuid(buf); } } return is; }
/** * @brief Deserialize the integer value from the specified input stream. * @param __s Reference to the input stream. */ void load(std::basic_istream<CharT, Traits> &__s) { // We must ensure that subsequent actions will be performed // for very likely integer value, otherwise and exception // should be raised. if (__s.peek() != basic_value_type::integer_token) { throw type_error( "bencode::integer::load the specified stream does " "not contain interpretable bencode integer value\n"); } // Read the leading "i" symbol from the provided stream. __s.get(); // Define the integer symbol representation placeholder. std::basic_stringstream<CharT, Traits> __i; // Define the input stream iterator of the provided stream to // be able to read the integer value symbol by symbol. auto __si = std::istream_iterator<CharT, CharT, Traits>(__s); // Define the output stream to as a buffer for the integer // value, which will be later converted. auto __ival = std::ostream_iterator<CharT, CharT, Traits>(__i); // Copy the values from the input stream into the integer // placeholder string stream. auto __result = copy_until(__si, __ival, [&__s](const CharT& __ch) { // Additionally, check that we did not exceed the // length of the stream to prevent hangs. return !__s.eof() && __ch != basic_value_type::end_token; }, basic_value_type::integer_length); // Covert the value from the string into the integer. __i >> _M_value; // The "e" symbol should be already extracted at this moment, // so validate that the iterator pointing right to it. if (*__result != basic_value_type::end_token) { std::ostringstream __error; __error << "bencode::integer::load the end of the integer " "`e` expected, but `" << CharT(*__result) << "` found\n"; throw encoding_error(__error.str()); } // Validate that decoded value is an actual integer. if (!_M_value && __i.str() != std::basic_string< CharT, Traits>(1, CharT('0'))) { std::ostringstream __error; __error << "bencode::integer::load the specified " "value is not a number\n"; throw value_error(__error.str()); } }
std::basic_string<CharT> ratio_string<Ratio, CharT>::prefix() { std::basic_ostringstream<CharT> os; os << CharT('[') << Ratio::num << CharT('/') << Ratio::den << CharT(']'); return os.str(); }
inline CharT toChar(const uint32_t digit) { if( 0 <= digit && digit <= 9 ) { return CharT('0')+(CharT)digit; } else if( 10 <= digit && digit < 36 ) { return CharT('a')+(CharT)(digit-10); } return CharT(0); }
hex_params( CharT zero_ch= CharT('0'), CharT a_ch= CharT('a'), bool leading_zeroes= true, bool non_empty= true, str_t const & prfx= str_t{} ) : zeroCh{ zero_ch } , aCh{ a_ch } , leadingZeroes{ leading_zeroes } , nonEmpty{ non_empty } , prefix{ prfx } {}
void duration_punct<CharT>::init_C() { short_seconds_ = CharT('s'); short_minutes_ = CharT('m'); short_hours_ = CharT('h'); const CharT s[] = {'s', 'e', 'c', 'o', 'n', 'd', 's'}; const CharT m[] = {'m', 'i', 'n', 'u', 't', 'e', 's'}; const CharT h[] = {'h', 'o', 'u', 'r', 's'}; long_seconds_.assign(s, s + sizeof(s)/sizeof(s[0])); long_minutes_.assign(m, m + sizeof(m)/sizeof(m[0])); long_hours_.assign(h, h + sizeof(h)/sizeof(h[0])); }
std::string lerpFromSide( const std::string& From, const std::string& To, const Real32& t) { UInt32 MaxSize(osgMax<UInt32>(From.size(),To.size())); Real32 TimePerChar(1.0f/static_cast<Real32>(MaxSize)); Real32 FromChar(' '),ToChar(' '); std::string Result(""); if(From.size() < To.size()) { //Left To Right Int32 Index(osgFloor<Int32>(static_cast<Real32>(MaxSize)*t)); Real32 CharT((t-Index*TimePerChar)/TimePerChar); Result = To.substr(0,osgMin<Int32>(To.size(),Index)); Result.resize(Index, ' '); if(Index<To.size()) { ToChar = To[Index]; } if(Index<From.size()) { FromChar = From[Index]; } Result += static_cast<Char8>(FromChar +( (ToChar - FromChar) * CharT )); //Interp Index Result += From.substr(osgMin<Int32>(Index+1,From.size()),std::string::npos); } else { //Right to Left Int32 Index(osgMax<Int32>(0,MaxSize - osgFloor(static_cast<Real32>(MaxSize)*t) - 1)); Real32 CharT((t-osgFloor<Int32>(static_cast<Real32>(MaxSize)*t)*TimePerChar)/TimePerChar); Result = From.substr(0,osgMin<Int32>(From.size(),Index)); Result.resize(Index, ' '); if(Index<To.size()) { ToChar = To[Index]; } if(Index<From.size()) { FromChar = From[Index]; } Result += static_cast<Char8>(FromChar +( (ToChar - FromChar) * CharT )); //Interp Index Result += To.substr(osgMin<Int32>(Index+1,To.size()),std::string::npos); } return Result; }
inline CharT *toStr(CharT *s, const size_t maxsize, const uint32_t num, const int base) { if( base < 2 || base > 36 ) { return 0; } uint32_t compnum = num; size_t reqsize = 0; do { reqsize++; compnum /= BASE; } while( compnum != 0 ); if( reqsize+1 > maxsize ) { return 0; } s[reqsize] = CharT(0); compnum = num; size_t i = 0; do { s[reqsize-i-1] = toChar<CharT>(compnum % BASE); i++; compnum /= BASE; } while( compnum != 0 ); return s; }
CharT letter_to_hex(CharT in) { switch (in) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': return in - '0'; case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': return in + 10 - 'a'; case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': return in + 10 - 'A'; } return CharT(); }
/// \name Construction //@{ chainid_component(CharT id = CharT(' ')) : id_(id) { static_assert( std::is_integral<CharT>::value == true, "Only integral types are allowed :("); }
iter_type put_unit(duration_units<CharT> const& facet, iter_type s, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d) const { if (facet.template is_named_unit<Period>()) { string_type str = facet.get_unit(get_duration_style(ios), d); s=std::copy(str.begin(), str.end(), s); } else { *s++ = CharT('['); std::use_facet<std::num_put<CharT, iter_type> >(ios.getloc()).put(s, ios, fill, Period::num); *s++ = CharT('/'); std::use_facet<std::num_put<CharT, iter_type> >(ios.getloc()).put(s, ios, fill, Period::den); *s++ = CharT(']'); string_type str = facet.get_n_d_unit(get_duration_style(ios), d); s=std::copy(str.begin(), str.end(), s); } return s; }
const CharT *StrEndOf(const CharT *pszBegin) noexcept { ASSERT(pszBegin); auto pchEnd = pszBegin; while(*pchEnd != CharT()){ ++pchEnd; } return pchEnd; }
static std::size_t length( const_char* cstr ) { const_char null_char = CharT(); const_char* ptr = cstr; while( !eq( *ptr, null_char ) ) ++ptr; return ptr - cstr; }
bool nsTString_CharT::SetCharAt( PRUnichar aChar, PRUint32 aIndex ) { if (aIndex >= mLength) return PR_FALSE; EnsureMutable(); mData[aIndex] = CharT(aChar); return PR_TRUE; }
bool nsTString_CharT::SetCharAt( char16_t aChar, uint32_t aIndex ) { if (aIndex >= mLength) return false; if (!EnsureMutable()) NS_ABORT_OOM(mLength); mData[aIndex] = CharT(aChar); return true; }
bool nsTString_CharT::SetCharAt( PRUnichar aChar, uint32_t aIndex ) { if (aIndex >= mLength) return false; if (!EnsureMutable()) NS_RUNTIMEABORT("OOM"); mData[aIndex] = CharT(aChar); return true; }
void TestHelper<CharT, 4>::test() { static_assert((std::is_same<CharT, wchar_t>::value), ""); { std::wstring_convert<std::codecvt_utf8<CharT> > myconv; std::wstring ws(1, CharT(0x40003)); std::string bs = myconv.to_bytes(ws[0]); assert(bs == "\xF1\x80\x80\x83"); bs = myconv.to_bytes(ws.c_str()); assert(bs == "\xF1\x80\x80\x83"); bs = myconv.to_bytes(ws); assert(bs == "\xF1\x80\x80\x83"); bs = myconv.to_bytes(ws.data(), ws.data() + ws.size()); assert(bs == "\xF1\x80\x80\x83"); bs = myconv.to_bytes(L""); assert(bs.size() == 0); } }
basic_ostream<CharT, TraitsT>& operator<<(basic_ostream<CharT, TraitsT>& stream, const brig::blob_t& blob) { if (stream.flags() & ios::hex) { const size_t width(size_t(stream.width())); const size_t size(blob.size()); const size_t count(width == 0? size: min<>(width / 2, size)); basic_ostringstream<CharT, TraitsT> s; s.imbue(locale::classic()); s << hex << setfill(CharT(0x30)); // DIGIT ZERO if (stream.flags() & ios::uppercase) s << uppercase; for (size_t i(0); i < count; ++i) s << setw(2) << static_cast<int>(blob[i]); stream << s.str(); } else { static const CharT prefix[] = { 0x42, 0x4c, 0x4f, 0x42, 0x20, 0x73, 0x7a, 0x20, 0x3d, 0x20, 0 }; // "BLOB sz = " stream << prefix << blob.size(); } return stream; }
std::basic_string<CharT> to_basic_string() const { std::basic_ostringstream<CharT> result; result << CharT('['); auto it = this->cbegin(); if (it != this->cend()) { result << *it; ++it; while (it != this->cend()) { result << CharT(' '); result << CharT('-'); result << CharT('>'); result << CharT(' '); result << *it; ++it; } } result << CharT(']'); return result.str(); }
/** * @brief Deserialize the string value from the specified input stream. * @param __s Reference to the input stream. */ void load(std::basic_istream<CharT, Traits>& __s) { // Define the integer symbol representation placeholder. std::basic_stringstream<CharT, Traits> __i; // Define the input stream iterator of the provided stream to // be able to read the string length value symbol by symbol. auto __si = std::istream_iterator<CharT, CharT, Traits>(__s); // Define the output stream to as a buffer for the integer // value, which will be later converted. auto __ival = std::ostream_iterator<CharT, CharT, Traits>(__i); // Copy the symbols from the input stream to the integer // placeholder until the ":" delimiter value. auto __result = copy_until(__si, __ival, [&__s](const CharT& __ch) { // Additionally, check that we did not exceed the // length of the stream to prevent hangs. return !__s.eof() && __ch != basic_value_type::delimiter_token; }, basic_value_type::integer_length); if (*__result != basic_value_type::delimiter_token) { std::ostringstream __error; __error << "bencode::string::load the delimiter `:` " "expected, but `" << CharT(*__result) << "` found\n"; throw encoding_error(__error.str()); } // Save the length of the string. int64_t __count; __i >> __count; if (!__count && __i.str() != std::basic_string< CharT, Traits>(1, CharT('0'))) { std::ostringstream __error; __error << "bencode::string::load the specified string " "length is not a number\n"; throw value_error(__error.str()); } // Ensure that the string length is a non-negative value. if (__count < 0) { std::ostringstream __error; __error << "bencode::string::load the length of the string " "value must be a positive integer: `" << __count << "`\n"; throw value_error(__error.str()); } // Allocate the list of symbols of the specified string length. std::unique_ptr<CharT[]> __str(new CharT[__count+1]); // Read the string value into the symbol list. __s.get(__str.get(), std::streamsize(__count+1)); auto __strval = string_type(__str.get()); // Ensure that valid count of the symbols was extracted from // the provided input stream. if (int64_t(__strval.length()) != __count) { std::ostringstream __error; __error << "bencode::string::load the specified string " "decoded length is not equal to the real one: `" << __count << "` != `" << __strval.length() << "`\n"; throw value_error(__error.str()); } // Initialize the internal value with a new string. _M_value = __strval; }
const std::locale make_locale (const CharT*, const LocaleData &data) { #if 255U == _RWSTD_UCHAR_MAX // work around a bogus gcc error: ISO C++ forbids variable-size // array (see https://issues.apache.org/jira/browse/STDCXX-351) static const std::size_t N = 256; #else // if UCHAR_MAX != 255 // determine the number of classic characters static const std::size_t N = std::ctype<char>::table_size; #endif // derive a class so we can call the protected classic_table() struct ClassicTable: std::ctype<char> { static const std::ctype_base::mask* get () { return classic_table (); } }; // get the classic C table of masks const std::ctype_base::mask* const classic = ClassicTable::get (); static int chars [N + 1]; static int masks [N + 1]; // -1 denotes end of characters (can't use 0 since it's a valid value) chars [N] = -1; // copy the classic table clearing the space bit of each mask for (std::size_t i = 0; i != N; ++i) { chars [i] = int (i); masks [i] = classic [i] & ~std::ctype_base::space; } typedef unsigned char UChar; // set the space bit for all characters in whitespace for (const char *ws = data.whitespace; *ws; ++ws) masks [UChar (*ws)] |= std::ctype_base::space; // create a user-defined ctype-derived facet and initialize // it with the character set and the specified masks const std::ctype<CharT>* const ctp = new UserCtype<CharT>(chars, masks); struct NumPunct: std::numpunct<CharT> { // CharType typedef works around a Sun C++ bug stdcxx-345 typedef CharT CharType; typedef std::numpunct<CharType> Base; typedef std::char_traits<CharType> Traits; typedef std::allocator<CharType> Allocator; typedef std::basic_string<CharType, Traits, Allocator> String; int dp_; int ts_; const char *grp_; const CharType *fn_; const CharType *tn_; NumPunct (int dp, int ts, const char *grp, const CharType *fn, const CharType *tn) : Base (), dp_ (dp), ts_ (ts), grp_ (grp ? grp : ""), fn_ (fn), tn_ (tn) { /* empty */ } CharType do_decimal_point () const { return -1 == dp_ ? Base::do_decimal_point () : make_char (char (dp_), (CharType*)0); } CharType do_thousands_sep () const { return -1 == ts_ ? Base::do_thousands_sep () : make_char (char (ts_), (CharType*)0); } std::string do_grouping () const { return 0 == grp_ ? Base::do_grouping () : std::string (grp_); } String do_truename () const { return 0 == tn_ ? Base::do_truename () : String (tn_); } String do_falsename () const { return 0 == fn_ ? Base::do_falsename () : String (fn_); } }; static CharT names [2][64]; names [false][0] = CharT (); names [true][0] = CharT (); if (data.falsename) { for (std::size_t i = 0; data.falsename [i]; ++i) { names [false][i] = data.falsename [i]; names [false][i + 1] = CharT (); } } if (data.truename) { for (std::size_t i = 0; data.truename [i]; ++i) { names [true][i] = data.truename [i]; names [true][i + 1] = CharT (); } } // create a user-defined numpunct-derived facet and initialize // its members with the specified parameters const std::numpunct<CharT>* const np = new NumPunct (data.decimal_point, data.thousands_sep, data.grouping, data.falsename ? names [false] : 0, data.truename ? names [true] : 0); // install the new nupunct facet in a temporary locale, // replacing the original (if CharT=char or CharT=wchar_t) const std::locale tmp (std::locale::classic (), np); // install the new ctype facet in a locale, replacing // the original (if CharT=char or CharT=wchar_t) return std::locale (tmp, ctp); }
multiText += _msgBoxLine(*it, width) + Const::nl(); } } writeLine(); writeLine(Format::str(xT("+{}+"), std::tstring_t(width - 2, xT('-')))); writeLine(Format::str(xT("|{}|"), std::tstring_t(width - 2, xT(' ')))); write(title); writeLine(Format::str(xT("|{}|"), std::tstring_t(width - 2, xT(' ')))); write(multiText); writeLine(Format::str(xT("|{}|"), std::tstring_t(width - 2, xT(' ')))); writeLine(Format::str(xT("+{}+"), std::tstring_t(width - 2, xT('-')))); writeLine(); write(Format::str(xT("\nAbort ({}), Ignore ({}), Retry ({}): "), cmdAbort, cmdIgnore, cmdRetry)); ctchar_t consoleCmd = CharT( static_cast<ctchar_t>(std::tcin.get()) ).toLower(); std::tcin.ignore(); switch (consoleCmd) { case cmdAbort: mrRv = mrAbort; writeLine(xT("Abort...")); break; case cmdIgnore: mrRv = mrIgnore; writeLine(xT("Ignore...")); break; case cmdRetry: mrRv = mrRetry; writeLine(xT("Retry...")); break;
bool join_sub_string ( const basic_cstring_view<CharT, Traits>& in, typename basic_cstring_view<CharT, Traits>::size_type& pos, std::basic_string<CharT, Traits, Allocator>& out, InputIterator valuesBegin, InputIterator valuesEnd, bool optional ) { using string_type = std::basic_string<CharT, Traits, Allocator>; using size_type = typename string_type::size_type; bool escapeChar = false; bool replacedAllValues = true; const auto numValues = static_cast<size_type>(std::distance(valuesBegin, valuesEnd)); if (numValues < 0) throw std::invalid_argument("reversed range iterators in join_string"); for (auto num = in.size(); pos < num;) { /* Get next character */ auto c = in[pos++]; if (escapeChar) { /* Add character without transformation to output string */ out.push_back(c); escapeChar = false; } else { if (c == CharT('\\')) { /* Next character will be added without transformation */ escapeChar = true; } else if (c == CharT('{')) { /* Parse index N in '{N}' */ string_type idxStr; while (pos < num) { /* Get next character */ c = in[pos++]; if (c == CharT('}')) break; else idxStr.push_back(c); } /* Get value by index from array */ const auto idx = static_cast<size_type>(std::stoul(idxStr)); if (idx < numValues) { /* Append value to output string */ const auto& val = *(valuesBegin + idx); if (string_empty(val)) replacedAllValues = false; else string_append(out, val); } else if (optional) { /* This sub string will not be added to the final output string */ replacedAllValues = false; } else { /* If this value replacement was not optional -> error */ throw std::out_of_range( "index (" + std::to_string(idx) + ") out of range [0, " + std::to_string(numValues) + ") in join_string" ); } } else if (c == CharT('[')) { /* Parse optional part with recursive call */ string_type outOpt; if (join_sub_string(in, pos, outOpt, valuesBegin, valuesEnd, true)) out.append(outOpt); } else if (c == CharT(']')) { /* Close optional part and return from recursive call */ break; } else { /* Add current character to output string */ out.push_back(c); } } } if (escapeChar) throw std::invalid_argument("incomplete escape character in report string"); return replacedAllValues; }