本文整理汇总了C++中cstring类的典型用法代码示例。如果您正苦于以下问题:C++ cstring类的具体用法?C++ cstring怎么用?C++ cstring使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了cstring类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
void
config_file_iterator::Impl::substitute_macros( cstring& where )
{
m_post_subst_line.clear();
cstring::size_type pos;
while( (pos = where.find( m_macro_ref_begin )) != cstring::npos ) {
m_post_subst_line.append( where.begin(), pos );
where.trim_left( where.begin() + pos + m_macro_ref_begin.size() );
pos = where.find( m_macro_ref_end );
BOOST_RT_PARAM_VALIDATE_LOGIC( pos != cstring::npos, BOOST_RT_PARAM_LITERAL( "incomplete macro reference" ) );
cstring value = *get_macro_value( where.substr( 0, pos ), false );
m_post_subst_line.append( value.begin(), value.size() );
where.trim_left( where.begin() + pos + m_macro_ref_end.size() );
}
if( !m_post_subst_line.empty() ) {
m_post_subst_line.append( where.begin(), where.size() );
where = m_post_subst_line;
}
}
示例2: m_parent
include_level::include_level( cstring file_name, cstring path_separators, include_level* parent_ )
: m_parent( parent_ )
{
if( file_name.is_empty() )
return;
assign_op( m_curr_location.first, file_name, 0 );
m_curr_location.second = 0;
m_stream.open( m_curr_location.first.c_str() );
if( !m_stream.is_open() && !!m_parent.get() ) {
cstring parent_path = m_parent->m_curr_location.first;
cstring::iterator it = unit_test::find_last_of( parent_path.begin(), parent_path.end(),
path_separators.begin(),
path_separators.end() );
if( it != parent_path.end() ) {
assign_op( m_curr_location.first, cstring( parent_path.begin(), it+1 ), 0 );
m_curr_location.first.append( file_name.begin(), file_name.end() );
m_stream.clear();
m_stream.open( m_curr_location.first.c_str() );
}
}
BOOST_RT_PARAM_VALIDATE_LOGIC( m_stream.is_open(), BOOST_RT_PARAM_LITERAL( "couldn't open file " ) << file_name );
}
示例3: _
static bool _( cstring source, boost::optional<bool>& res )
{
BOOST_RT_PARAM_TRACE( "In interpret_argument_value_impl<bool>" );
static literal_cstring YES( BOOST_RT_PARAM_CSTRING_LITERAL( "YES" ) );
static literal_cstring Y( BOOST_RT_PARAM_CSTRING_LITERAL( "Y" ) );
static literal_cstring NO( BOOST_RT_PARAM_CSTRING_LITERAL( "NO" ) );
static literal_cstring N( BOOST_RT_PARAM_CSTRING_LITERAL( "N" ) );
static literal_cstring one( BOOST_RT_PARAM_CSTRING_LITERAL( "1" ) );
static literal_cstring zero( BOOST_RT_PARAM_CSTRING_LITERAL( "0" ) );
source.trim();
if( case_ins_eq( source, YES ) || case_ins_eq( source, Y ) || case_ins_eq( source, one ) ) {
res = true;
return true;
}
else if( case_ins_eq( source, NO ) || case_ins_eq( source, N ) || case_ins_eq( source, zero ) ) {
res = false;
return true;
}
else {
res = true;
return source.is_empty();
}
}
示例4: putenv_impl
inline void
putenv_impl( cstring name, cstring value )
{
using namespace std;
// !! this may actually fail. What should we do?
setenv( name.begin(), value.begin(), 1 );
}
示例5: interpret
bool interpret( cstring param_name, cstring source ) const
{
static cstring const s_YES( "YES" );
static cstring const s_Y( "Y" );
static cstring const s_NO( "NO" );
static cstring const s_N( "N" );
static cstring const s_TRUE( "TRUE" );
static cstring const s_FALSE( "FALSE" );
static cstring const s_one( "1" );
static cstring const s_zero( "0" );
source.trim();
if( source.is_empty() ||
case_ins_eq( source, s_YES ) ||
case_ins_eq( source, s_Y ) ||
case_ins_eq( source, s_one ) ||
case_ins_eq( source, s_TRUE ) )
return true;
if( case_ins_eq( source, s_NO ) ||
case_ins_eq( source, s_N ) ||
case_ins_eq( source, s_zero ) ||
case_ins_eq( source, s_FALSE ) )
return false;
BOOST_TEST_I_THROW( format_error( param_name ) << source << " can't be interpreted as bool value." );
}
示例6: fromstringhex
bool fromstringhex(cstring s, arrayvieww<byte> val)
{
if (val.size()*2 != s.length()) return false;
bool ok = true;
for (size_t i=0;i<val.size();i++)
{
ok &= fromstringhex(s.substr(i*2, i*2+2), val[i]);
}
return ok;
}
示例7: translateRk86
string translateRk86(cstring in) {
string out;
out.resize(in.size());
const char* inp = in.c_str();
char* o = (char*)out.c_str();
while(*inp) {
char c = translateRk86c(*inp++);
if(c==0) raise("Имя файла "+in+" содержит неподдерживаемый РК86 символ.");
*o++ = c;
}
return out;
}
示例8: type_core
bmlwriter::mode bmlwriter::type_core(cstring val)
{
if (val == "") return anon;
char first = val[0];
char last = val[val.length()-1];
if (val.contains("\n") || first==' ' || first=='\t' || last==' ' || last=='\t') return multiline;
if (val.contains("\"")) return col;
if (val.contains(" ") || val.contains("\t")) return quote;
return eq;
}
示例9: escape
string bmlwriter::escape(cstring val)
{
string esc = "-";
bool needescape = (val.startswith("-"));
for (byte c : val.bytes())
{
if (isalnum(c) || c=='.') esc+=c;
else if (c=='-') esc+="--";
else { esc+="-"+tostringhex<2>((uint8_t)c); needescape=true; }
}
if (needescape) return esc;
else return val;
}
示例10: fromstring
bool fromstring(cstring s, double& out)
{
out = 0;
auto tmp_s = s.c_str();
const char * tmp_cp = tmp_s;
if (*tmp_cp != '-' && !isdigit(*tmp_cp)) return false;
char * tmp_cpo;
double ret = strtod(drop0x(tmp_cp), &tmp_cpo);
if (tmp_cpo != tmp_cp + s.length()) return false;
if (!isdigit(tmp_cpo[-1])) return false;
if (ret==HUGE_VAL || ret==-HUGE_VAL) return false;
out = ret;
return true;
}
示例11: basic_param
basic_param( cstring name, bool is_optional, bool is_repeatable, Modifiers const& m )
: p_name( name.begin(), name.end() )
, p_description( nfp::opt_get( m, description, std::string() ) )
, p_help( nfp::opt_get( m, runtime::help, std::string() ) )
, p_env_var( nfp::opt_get( m, env_var, std::string() ) )
, p_value_hint( nfp::opt_get( m, value_hint, std::string() ) )
, p_optional( is_optional )
, p_repeatable( is_repeatable )
, p_has_optional_value( m.has( optional_value ) )
, p_has_default_value( m.has( default_value ) || is_repeatable )
, p_callback( nfp::opt_get( m, callback, callback_type() ) )
{
add_cla_id( help_prefix, name, ":" );
}
示例12: linelen
static size_t linelen(const cstring& input)
{
//pointers are generally a bad idea, but this is such a hotspot it's worth it
const uint8_t * inputraw = input.bytes().ptr();
size_t nlpos = 0;
if (input.bytes_hasterm())
{
while (!isendl(inputraw[nlpos])) nlpos++;
}
else
{
size_t inputlen = input.length();
while (nlpos < inputlen && !isendl(inputraw[nlpos])) nlpos++;
}
return nlpos;
}
示例13: bml_size_white
//returns size of leading whitespace and comments
static size_t bml_size_white(const cstring& data)
{
int i = 0;
while (data[i]==' ' || data[i]=='\t') i++;
if (data[i]=='#' || (data[i]=='/' && data[i+1]=='/')) return data.length();
else return i;
}
示例14: is_valid_identifier
static bool
is_valid_identifier( cstring const& source )
{
if( source.is_empty() )
return false;
cstring::const_iterator it = source.begin();
if( !std::isalpha( *it ) )
return false;
while( ++it < source.end() ) {
if( !std::isalnum( *it ) && *it != BOOST_RT_PARAM_LITERAL( '_' ) && *it != BOOST_RT_PARAM_LITERAL( '-' ) )
return false;
}
return true;
}
示例15: while
cstring ReferenceMap::newName(cstring base) {
// Maybe in the future we'll maintain information with per-scope identifiers,
// but today we are content to generate globally-unique identifiers.
// If base has a suffix of the form _(\d+), then we discard the suffix.
// under the assumption that it is probably a generated suffix.
// This will not impact correctness.
unsigned len = base.size();
const char digits[] = "0123456789";
const char* s = base.c_str();
while (len > 0 && strchr(digits, s[len-1])) len--;
if (len > 0 && base[len - 1] == '_')
base = base.substr(0, len - 1);
cstring name = cstring::make_unique(usedNames, base, '_');
usedNames.insert(name);
return name;
}