void OprtCastToStr::Eval(ptr_val_type &ret, const ptr_val_type *a_pArg, int /*a_iArgc*/) { CodaScriptBackingStore* Store = a_pArg[0]->GetStore(); SME_ASSERT(Store); char Buffer[0x512] = {0}; switch(Store->GetType()) { case ICodaScriptDataStore::kDataType_Numeric: sprintf_s(Buffer, sizeof(Buffer), "%0.6f", Store->GetNumber()); *ret = string_type(Buffer); break; case ICodaScriptDataStore::kDataType_Reference: sprintf_s(Buffer, sizeof(Buffer), "%08X", Store->GetFormID()); *ret = string_type(Buffer); break; case ICodaScriptDataStore::kDataType_String: *ret = string_type(Store->GetString()); break; default: { ErrorContext err; err.Errc = ecINVALID_TYPECAST; err.Type1 =Store->GetType(); err.Type2 = ICodaScriptDataStore::kDataType_String; throw ParserError(err); } } }
static std::deque<string_type> tokenize(string_type input, string_type br) { typename string_type::iterator a,b,c; std::deque<string_type> tokens; // std::cerr << "Tokenising string=" << input << " break=" << br << std::endl; while ( input.length() ) { a = input.begin(); c = input.end(); typename string_type::size_type e = input.find(br); if ( e != string_type::npos ) { b = a+e; tokens.push_back(string_type(a,b)); input = string_type(b+br.length(),c); } else { tokens.push_back(input); input = string_type(); } // std::cerr << "Pushed token " << tokens.back() << " input now " << input << std::endl; } return tokens; }
string_type to_string() const { if (_data != nullptr) return string_type(_data); else return string_type(); }
c_regex_traits<wchar_t>::string_type BOOST_REGEX_CALL c_regex_traits<wchar_t>::lookup_collatename(const wchar_t* p1, const wchar_t* p2) { #if !defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS)\ && !BOOST_WORKAROUND(BOOST_MSVC, < 1300)\ && !BOOST_WORKAROUND(__BORLANDC__, <= 0x0551) std::string name(p1, p2); #else std::string name; const wchar_t* p0 = p1; while(p0 != p2) name.append(1, char(*p0++)); #endif name = ::boost::re_detail::lookup_default_collate_name(name); #if !defined(BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS)\ && !BOOST_WORKAROUND(BOOST_MSVC, < 1300)\ && !BOOST_WORKAROUND(__BORLANDC__, <= 0x0551) if(name.size()) return string_type(name.begin(), name.end()); #else if(name.size()) { string_type result; typedef std::string::const_iterator iter; iter b = name.begin(); iter e = name.end(); while(b != e) result.append(1, wchar_t(*b++)); return result; } #endif if(p2 - p1 == 1) return string_type(1, *p1); return string_type(); }
/** \brief Check if a string position contains a binary operator. \param a_Tok [out] Operator token if one is found. This can either be a binary operator or an infix operator token. \return true if an operator token has been found. */ bool ParserTokenReader::IsOprt(token_type &a_Tok) { const char_type *const szExpr = m_strFormula.c_str(); string_type strTok; int iEnd = ExtractOperatorToken(strTok, m_iPos); if (iEnd==m_iPos) return false; // Check if the operator is a built in operator, if so ignore it here const char_type **const pOprtDef = m_pParser->GetOprtDef(); for (int i=0; m_pParser->HasBuiltInOprt() && pOprtDef[i]; ++i) { if (string_type(pOprtDef[i])==strTok) return false; } // Note: // All tokens in oprt_bin_maptype are have been sorted by their length // Long operators must come first! Otherwise short names (like: "add") that // are part of long token names (like: "add123") will be found instead // of the long ones. // Length sorting is done with ascending length so we use a reverse iterator here. funmap_type::const_reverse_iterator it = m_pOprtDef->rbegin(); for ( ; it!=m_pOprtDef->rend(); ++it) { const string_type &sID = it->first; if ( sID == string_type(szExpr + m_iPos, szExpr + m_iPos + sID.length()) ) { a_Tok.Set(it->second, strTok); // operator was found if (m_iSynFlags & noOPT) { // An operator was found but is not expected to occur at // this position of the formula, maybe it is an infix // operator, not a binary operator. Both operator types // can share characters in their identifiers. if ( IsInfixOpTok(a_Tok) ) return true; else { // nope, no infix operator return false; //Error(ecUNEXPECTED_OPERATOR, m_iPos, a_Tok.GetAsString()); } } m_iPos += (int)sID.length(); m_iSynFlags = noBC | noOPT | noARG_SEP | noPOSTOP | noEND | noBC | noASSIGN; return true; } } return false; }
icu_regex_traits_implementation::string_type icu_regex_traits_implementation::do_transform(const char_type* p1, const char_type* p2, const U_NAMESPACE_QUALIFIER Collator* pcoll) const { // TODO make thread safe!!!! : typedef u32_to_u16_iterator<const char_type*, ::UChar> itt; itt i(p1), j(p2); #ifndef BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS std::vector< ::UChar> t(i, j); #else std::vector< ::UChar> t; while(i != j) t.push_back(*i++); #endif ::uint8_t result[100]; ::int32_t len; if(t.size()) len = pcoll->getSortKey(&*t.begin(), static_cast< ::int32_t>(t.size()), result, sizeof(result)); else len = pcoll->getSortKey(static_cast<UChar const*>(0), static_cast< ::int32_t>(0), result, sizeof(result)); if(std::size_t(len) > sizeof(result)) { scoped_array< ::uint8_t> presult(new ::uint8_t[len+1]); if(t.size()) len = pcoll->getSortKey(&*t.begin(), static_cast< ::int32_t>(t.size()), presult.get(), len+1); else len = pcoll->getSortKey(static_cast<UChar const*>(0), static_cast< ::int32_t>(0), presult.get(), len+1); if((0 == presult[len-1]) && (len > 1)) --len; #ifndef BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS return string_type(presult.get(), presult.get()+len); #else string_type sresult; ::uint8_t const* ia = presult.get(); ::uint8_t const* ib = presult.get()+len; while(ia != ib) sresult.push_back(*ia++); return sresult; #endif } if((0 == result[len-1]) && (len > 1)) --len; #ifndef BOOST_NO_TEMPLATED_ITERATOR_CONSTRUCTORS return string_type(result, result+len); #else string_type sresult; ::uint8_t const* ia = result; ::uint8_t const* ib = result+len; while(ia != ib) sresult.push_back(*ia++); return sresult; #endif }
static std::pair<string_type,string_type> tokenizePair(string_type input, string_type br) { std::deque<string_type> tokens = tokenize<string_type>(input,br); if ( tokens.size() == 0 ) return std::pair<string_type,string_type>( string_type(), string_type()); else if ( tokens.size() == 1 ) return std::pair<string_type,string_type>( string_type(tokens[0]), string_type()); else if ( tokens.size() == 2 ) return std::pair<string_type,string_type>( string_type(tokens[0]), string_type(tokens[1])); else { string_type val; for ( uint64_t i = 1; i < tokens.size(); ++i ) { val += tokens[i]; if ( i+1 < tokens.size() ) val += br; } return std::pair<string_type,string_type>( string_type(tokens[0]), string_type(val)); } }
inline Token xpressive_lexer<Iterator, Token, Callback>::next_token( Iterator &first, Iterator const& last, string_type& token) { typedef typename regex_list_type::iterator iterator; xpressive::match_results<Iterator> regex_result; for (iterator it = regex_list.begin(), end = regex_list.end(); it != end; ++it) { namespace xpressive = boost::xpressive; // regex_info const& curr_regex = *it; // xpressive::match_results<Iterator> regex_result; if (xpressive::regex_search(first, last, regex_result, (*it).regex, xpressive::regex_constants::match_continuous)) { Iterator saved = first; Token rval = (*it).token; std::advance(first, regex_result.length()); token = string_type(saved, first); if (NULL != (*it).callback) { // execute corresponding callback if ((*it).callback(saved, first, last, (*it).token)) rval = next_token(first, last, token); } return rval; } } return Token(-1); // TODO: change this to use token_traits<Token> }
void default_filter_factory< CharT >::on_string_argument( string_type const& name, const char_type* b, const char_type* e, filter_type& filter) { filter = log::filters::attr< string_type >(name, std::nothrow).satisfies(log::aux::bind2nd(RelationT(), string_type(b, e))); }
//------------------------------------------------------------------------------ string_type ParserErrorMsg::GetErrorMsg(EErrorCodes eError) const { if (!m_pInstance.get()) return string_type(); else return m_pInstance->GetErrorMsg(eError); }
void uri_builder::set_host(string_type host) { host_.reset(string_type()); auto end = network::uri::encode_host(std::begin(host), std::end(host), std::back_inserter(*host_)); std::transform(std::begin(*host_), std::end(*host_), std::begin(*host_), [](string_type::value_type c) { return std::tolower(c); }); }
bool nsTSubstring_CharT::Assign( const substring_tuple_type& tuple, const fallible_t& ) { if (tuple.IsDependentOn(mData, mData + mLength)) { // take advantage of sharing here... return Assign(string_type(tuple), fallible_t()); } size_type length = tuple.Length(); // don't use ReplacePrep here because it changes the length char_type* oldData; uint32_t oldFlags; if (!MutatePrep(length, &oldData, &oldFlags)) return false; if (oldData) ::ReleaseData(oldData, oldFlags); tuple.WriteTo(mData, length); mData[length] = 0; mLength = length; return true; }
/** * Look up a prefix and get the currently-mapped Namespace URI. * * <p>This method looks up the prefix in the current context. * Use the empty string ("") for the default Namespace.</p> * * @param prefix The prefix to look up. * @return The associated Namespace URI, or empty string if the prefix * is undeclared in this context. * @see #getPrefix * @see #getPrefixes */ string_type getURI(const string_type& prefix) const { for(typename contextListT::const_reverse_iterator i = contexts_.rbegin(); i != contexts_.rend(); ++i) { typename stringMapT::const_iterator u = i->find(prefix); if(u != i->end()) return u->second; } // for ... return string_type(); } // getURI
/** * Return one of the prefixes mapped to a Namespace URI. * * <p>If more than one prefix is currently mapped to the same * URI, this method will make an arbitrary selection; if you * want all of the prefixes, use the {@link #getPrefixes} * method instead.</p> * * <p><strong>Note:</strong> this will never return the empty (default) prefix; * to check for a default prefix, use the {@link #getURI getURI} * method with an argument of "".</p> * * @param uri The Namespace URI. * @return One of the prefixes currently mapped to the URI supplied, * or an empty string if none is mapped or if the URI is assigned to * the default Namespace. * @see #getPrefixes(const string_type&) * @see #getURI */ string_type getPrefix(const string_type& uri) const { for(typename contextListT::const_reverse_iterator i = contexts_.rbegin(); i != contexts_.rend(); ++i) { for(typename stringMapT::const_iterator u = i->begin(); u != i->end(); ++u) if(u->second == uri) return u->first; } // for ... return string_type(); } // getPrefix
printable_string* make_printable_string(unsigned char* val) { printable_string* result = ALLOCATE(sizeof(printable_string)); size_t len = strlen(val) + 1; unsigned char* copy = ALLOCATE(sizeof(unsigned char*) * len); printable* presult = (printable*)result; strncpy(copy, val, len - 1); copy[len - 1] = '\0'; presult->type = string_type(); presult->val = copy; presult->size = len; define_method(presult->type, to_string, to_string_string); return result; }
void encode(const double latitude, const double longitude, unsigned long precision, string_type & output) { // DecodedBBox for the lat/lon + errors DecodedBBox bbox; bbox.maxlat = 90; bbox.maxlon = 180; bbox.minlat = -90; bbox.minlon = -180; double mid = 0; bool islon = true; int num_bits = 0; int hash_index = 0; // Pre-Allocate the hash string output = string_type(precision, ' '); unsigned int output_length = 0; while(output_length < precision) { if (islon) { mid = (bbox.maxlon + bbox.minlon) / 2; if(longitude > mid) { hash_index = (hash_index << 1) + 1; bbox.minlon=mid; } else { hash_index = (hash_index << 1) + 0; bbox.maxlon=mid; } } else { mid = (bbox.maxlat + bbox.minlat) / 2; if(latitude > mid ) { hash_index = (hash_index << 1) + 1; bbox.minlat = mid; } else { hash_index = (hash_index << 1) + 0; bbox.maxlat = mid; } } islon = !islon; ++num_bits; if (5 == num_bits) { // Append the character to the pre-allocated string // This gives us roughly a 2x speed boost output[output_length] = base32_codes[hash_index]; output_length++; num_bits = 0; hash_index = 0; } } };
std::vector<string_type> to_vector() const { if (_data == nullptr) return std::vector<string_type>(); std::vector<string_type> data; auto str = string_type(_data); struct splitter { bool operator()(wchar_t w) const {return w == api::env_seperator<wchar_t>();} bool operator()(char c) const {return c == api::env_seperator<char> ();} } s; boost::split(data, _data, s); return std::move(data); }
collate_byname<char>::string_type collate_byname<char>::do_transform(const char* low, const char* high) const { if (low == high) return string_type(); size_t n = _Locale_strxfrm(_M_collate, NULL, 0, low, high - low); // NOT PORTABLE. What we're doing relies on internal details of the // string implementation. (Contiguity of string elements and presence // of trailing zero.) string_type buf(n, 0); _Locale_strxfrm(_M_collate, &(*buf.begin()), n + 1, low, high - low); return buf; }
collate_byname<char>::string_type collate_byname<char>::do_transform(const char* low, const char* high) const { size_t n = _Locale_strxfrm(_M_collate, NULL, 0, low, high - low); __vector__<char, allocator<char> > buf(n); _Locale_strxfrm(_M_collate, &buf.front(), n, low, high - low); char& __c1 = *(buf.begin()); char& __c2 = (n == (size_t)-1) ? *(buf.begin() + (high-low-1)) : *(buf.begin() + n); // char& __c2 = *(buf.begin() + n); return string_type( &__c1, &__c2 ); }
/** \brief Extract all characters that belong to a certain charset. \param a_szCharSet [in] Const char array of the characters allowed in the token. \param a_strTok [out] The string that consists entirely of characters listed in a_szCharSet. \param a_iPos [in] Position in the string from where to start reading. \return The Position of the first character not listed in a_szCharSet. \throw nothrow */ int ParserTokenReader::ExtractToken(const char_type *a_szCharSet, string_type &a_sTok, int a_iPos) const { int iEnd = (int)m_strFormula.find_first_not_of(a_szCharSet, a_iPos); if (iEnd==(int)string_type::npos) iEnd = (int)m_strFormula.length(); // Assign token string if there was something found if (a_iPos!=iEnd) a_sTok = string_type( m_strFormula.begin()+a_iPos, m_strFormula.begin()+iEnd); return iEnd; }
void nsTSubstring_CharT::AssignASCII( const char* data, size_type length ) { // A Unicode string can't depend on an ASCII string buffer, // so this dependence check only applies to CStrings. #ifdef CharT_is_char if (IsDependentOn(data, data + length)) { // take advantage of sharing here... Assign(string_type(data, length)); return; } #endif if (ReplacePrep(0, mLength, length)) char_traits::copyASCII(mData, data, length); }
path& path::append(const path& p) { if (p.empty()) return *this; if (empty()) { return (*this = p); } invalidate(); // check for something stupid like xx.append(xx); if (&p == this) { return append_common(string_type(p._path)); } return append_common(p._path); }
BOOST_LOG_API void basic_record_ostream< CharT >::init_stream() { base_type::imbue(std::locale()); if (m_record) { typedef attributes::attribute_value_impl< string_type > message_impl_type; intrusive_ptr< message_impl_type > p = new message_impl_type(string_type()); attribute_value value(p); // This may fail if the record already has Message attribute std::pair< attribute_value_set::const_iterator, bool > res = m_record->attribute_values().insert(expressions::tag::message::get_name(), value); if (!res.second) const_cast< attribute_value& >(res.first->second).swap(value); base_type::attach(const_cast< string_type& >(p->get())); } }
bool nsTSubstring_CharT::AssignASCII( const char* data, size_type length, const fallible_t& ) { // A Unicode string can't depend on an ASCII string buffer, // so this dependence check only applies to CStrings. #ifdef CharT_is_char if (IsDependentOn(data, data + length)) { return Assign(string_type(data, length), fallible_t()); } #endif if (!ReplacePrep(0, mLength, length)) return false; char_traits::copyASCII(mData, data, length); return true; }
/** \brief Check whether the token at a given position is a value token. Value tokens are either values or constants. \param a_Tok [out] If a value token is found it will be placed here. \return true if a value token has been found. */ bool TokenReader::IsValTok(ptr_tok_type &a_Tok) { if (m_vValueReader.size() == 0) return false; stringstream_type stream(m_sExpr.c_str() + m_nPos); string_type sTok; try { // call the value recognition functions provided by the user // Call user defined value recognition functions int iSize = (int)m_vValueReader.size(); Value val; for (int i = 0; i < iSize; ++i) { int iStart = m_nPos; if (m_vValueReader[i]->IsValue(m_sExpr.c_str(), m_nPos, val)) { sTok.assign(m_sExpr.c_str(), iStart, m_nPos); if (m_nSynFlags & noVAL) throw ecUNEXPECTED_VAL; m_nSynFlags = noVAL | noVAR | noFUN | noBO | noIFX | noIO; a_Tok = ptr_tok_type(val.Clone()); a_Tok->SetIdent(string_type(sTok.begin(), sTok.begin() + (m_nPos - iStart))); return true; } } } catch (EErrorCodes e) { ErrorContext err; err.Errc = e; err.Pos = m_nPos; err.Ident = sTok; err.Expr = m_sExpr; err.Pos = m_nPos - (int)sTok.length(); throw ParserError(err); } return false; }
/** \brief Check Expression for the presence of a binary operator token. Userdefined binary operator "++" gives inconsistent parsing result for the equations "a++b" and "a ++ b" if alphabetic characters are allowed in operator tokens. To avoid this this function checks specifically for operator tokens. */ int ParserTokenReader::ExtractOperatorToken(string_type &a_sTok, int a_iPos) const { int iEnd = (int)m_strFormula.find_first_not_of(m_pParser->ValidInfixOprtChars(), a_iPos); if (iEnd==(int)string_type::npos) iEnd = (int)m_strFormula.length(); // Assign token string if there was something found if (a_iPos!=iEnd) { a_sTok = string_type( m_strFormula.begin() + a_iPos, m_strFormula.begin() + iEnd); return iEnd; } else { // There is still the chance of having to deal with an operator consisting exclusively // of alphabetic characters. return ExtractToken(MUP_CHARS, a_sTok, a_iPos); } }
int module_loader_op::write(shared_ptr<fs_entry> file_ent, char const *buf, size_t size, off_t offset) { int ret = size; auto request = string_type(buf, size); request_parser parser; if (parser.parse(request)) try { typedef core_file_system::priority priority; if (parser.get_command() == "load") for (auto&& mod_name : parser.get_args()) fs_root_->install_module(priority::normal, mod_name[0], paths_); else if (parser.get_command() == "unload") for (auto&& mod_name : parser.get_args()) fs_root_->uninstall_module(mod_name[0]); } catch (no_such_ops_type& e) { BOOST_LOG_TRIVIAL(error) << "module_loader: " << e.what(); throw_system_error(EINVAL); } else ret = -ENOTSUP; return ret; }
hdf5_oprimitive::write_hdf5_dataset ( const std::string *t, std::size_t data_count, std::size_t object_number ) { BOOST_ASSERT(data_count == 1); char const* c_string = t->c_str(); hdf5_datatype string_type(H5T_STRING); if(use_variable_length_strings_ || t->empty()) { string_type.resize(H5T_VARIABLE); write_dataset_basic(&c_string, data_count, string_type, object_number); } else { string_type.resize(t->size()); write_dataset_basic(c_string, data_count, string_type, object_number); } string_type.close(); }
bool nsTSubstring_CharT::Assign( const char_type* data, size_type length, const fallible_t& ) { if (!data) { Truncate(); return true; } if (length == size_type(-1)) length = char_traits::length(data); if (IsDependentOn(data, data + length)) { return Assign(string_type(data, length), fallible_t()); } if (!ReplacePrep(0, mLength, length)) return false; char_traits::copy(mData, data, length); return true; }
void nsTSubstring_CharT::Assign( const char_type* data, size_type length ) { // unfortunately, some callers pass null :-( if (!data) { Truncate(); return; } if (length == size_type(-1)) length = char_traits::length(data); if (IsDependentOn(data, data + length)) { // take advantage of sharing here... Assign(string_type(data, length)); return; } if (ReplacePrep(0, mLength, length)) char_traits::copy(mData, data, length); }