예제 #1
0
파일: BWString.cpp 프로젝트: cy2296/coding
// trim leading and trailing spaces
BWString & BWString::trim() {
    const static char * whitespace = "\x20\x1b\t\r\n\v\b\f\a";

    if(!have_value()) return *this;	// make sure we have a string

    size_t begin = 0;
    size_t end = length() - 1;

    for (begin = 0; begin <= end; ++begin) {
        if (strchr(whitespace, _str[begin]) == nullptr) {
            break;
        }
    }

    for ( ; end > begin; --end) {
        if (strchr(whitespace, _str[end]) == nullptr) {
            break;
        } else {
            _str[end] = '\0';
        }
    }

    if (begin) {
        for (size_t i = 0; _str[i]; ++i) {
            _str[i] = _str[begin++];
        }
    }

    _str_len = strlen(_str);
    return *this;
}
예제 #2
0
         void operator()(section const & v) const
         {
				const stache_variant* location = lookup(v.name);
				bool positive = have_value(location);
				if( positive && !v.is_inverted )
				{
					if (auto vec = get<stache_model_vector>(location))
					{
						for( const auto& entry : *vec )
						{
							const stache_model* m = boost::get<stache_model>(&entry);
							if( m )
							{
								stache_model_printer section_printer(out, *m, this);
								apply_visitor_to_root(section_printer, v.nodes);
							}
							else
							{
								apply_visitor_to_root(*this, v.nodes);
							}
						}
					}
					else if (auto model = get<stache_model>(location))
					{
						stache_model_printer section_printer(out, *model, this);
						apply_visitor_to_root(section_printer, v.nodes);
					}
					else
					{
						// This is the odd case that they requested a section, but it was
						// some non-mapped type.  We can handle this by recursively calling
						// the printer with the nodes of the section.  Dynamic lookup can
						// still find the section tag for proper display within the
						// section.
						apply_visitor_to_root(*this, v.nodes);
					}
				}
				else if( !positive && v.is_inverted )
				{
					apply_visitor_to_root(stache_model_printer(out, stache_model(), this), v.nodes);
				}
         }