Example #1
0
void test_strview_basics(const string_view& sv, const char *p, size_t n) {
    ASSERT_EQ(p, sv.data());
    ASSERT_EQ(n, sv.size());
    ASSERT_EQ(n, sv.length());
    ASSERT_EQ((n == 0), sv.empty());

    ASSERT_EQ(p, sv.cbegin());
    ASSERT_EQ(p, sv.begin());
    ASSERT_EQ(p + n, sv.cend());
    ASSERT_EQ(p + n, sv.end());

    using reviter_t = std::reverse_iterator<string_view::const_iterator>;

    ASSERT_EQ(reviter_t(sv.end()),    sv.rbegin());
    ASSERT_EQ(reviter_t(sv.begin()),  sv.rend());
    ASSERT_EQ(reviter_t(sv.cend()),   sv.crbegin());
    ASSERT_EQ(reviter_t(sv.cbegin()), sv.crend());

    for (size_t i = 0; i < n; ++i) {
        ASSERT_EQ(p[i], sv[i]);
        ASSERT_EQ(p[i], sv.at(i));
    }
    ASSERT_THROW(sv.at(n), std::out_of_range);
    ASSERT_THROW(sv.at(string_view::npos), std::out_of_range);

    if (n > 0) {
        ASSERT_EQ(p,         &(sv.front()));
        ASSERT_EQ(p + (n-1), &(sv.back()));
        ASSERT_EQ(p[0],        sv.front());
        ASSERT_EQ(p[n-1],      sv.back());
    }
}
Example #2
0
int main()
{
    using string_view    = std::experimental::string_view;
    using u16string_view = std::experimental::u16string_view;
    using u32string_view = std::experimental::u32string_view;
    using wstring_view   = std::experimental::wstring_view;

    test(string_view   {});
    test(string_view   { "123"});
    test(u16string_view{});
    test(u16string_view{u"123"});
    test(u32string_view{});
    test(u32string_view{U"123"});
    test(wstring_view  {});
    test(wstring_view  {L"123"});

    {
    constexpr string_view       sv { "123", 3 };
    constexpr u16string_view u16sv {u"123", 3 };
    constexpr u32string_view u32sv {U"123", 3 };
    constexpr wstring_view     wsv {L"123", 3 };
    
    static_assert (    sv.begin() !=    sv.end(), "" );
    static_assert ( u16sv.begin() != u16sv.end(), "" );
    static_assert ( u32sv.begin() != u32sv.end(), "" );
    static_assert (   wsv.begin() !=   wsv.end(), "" );

    static_assert (    sv.begin() !=    sv.cend(), "" );
    static_assert ( u16sv.begin() != u16sv.cend(), "" );
    static_assert ( u32sv.begin() != u32sv.cend(), "" );
    static_assert (   wsv.begin() !=   wsv.cend(), "" );
    }
}
Example #3
0
    string_view ParserKeyword::getDeckName( const string_view& str ) {

        auto first_sep = std::find_if( str.begin(), str.end(), RawConsts::is_separator() );

        // only look at the first 8 characters (at most)
        if( std::distance( str.begin(), first_sep ) < 9 )
            return { str.begin(), first_sep };

        return { str.begin(), str.begin() + 9 };
    }
string transcription::to_rna(string_view strand)
{
    string result;
    transform(strand.begin(), strand.end(), back_inserter(result),
        static_cast<char (*)(char)>(to_rna));
    return result;
}
Example #5
0
config_option::config_option(string_view category, string_view name,
                             string_view description, const meta_state* meta,
                             void* value)
    : meta_(meta),
      value_(value) {
  using std::copy;
  using std::accumulate;
  auto comma = name.find(',');
  auto long_name = name.substr(0, comma);
  auto short_names = comma == string_view::npos ? string_view{}
                                                : name.substr(comma + 1);
  auto total_size = [](std::initializer_list<string_view> xs) {
    return (xs.size() - 1) // one separator between all fields
           + accumulate(xs.begin(), xs.end(), size_t{0},
                        [](size_t x, string_view sv) { return x + sv.size(); });
  };
  auto ts = total_size({category, long_name, short_names, description});
  CAF_ASSERT(ts <= std::numeric_limits<uint16_t>::max());
  buf_size_ = static_cast<uint16_t>(ts);
  buf_.reset(new char[ts]);
  // fille the buffer with "<category>.<long-name>,<short-name>,<descriptions>"
  auto first = buf_.get();
  auto i = first;
  auto pos = [&] {
    return static_cast<uint16_t>(std::distance(first, i));
  };
  // <category>.
  i = copy(category.begin(), category.end(), i);
  category_separator_ = pos();
  *i++ = '.';
  // <long-name>,
  i = copy(long_name.begin(), long_name.end(), i);
  long_name_separator_ = pos();
  *i++ = ',';
  // <short-names>,
  i = copy(short_names.begin(), short_names.end(), i);
  short_names_separator_ = pos();
  *i++ = ',';
  // <description>
  i = copy(description.begin(), description.end(), i);
  CAF_ASSERT(pos() == buf_size_);
}
Example #6
0
    bool ParserKeyword::validDeckName( const string_view& name) {

        if( !validNameStart( name ) )
            return false;

        const auto valid = []( char c ) {
            return std::isalnum( c ) || c == '-' || c == '_' || c == '+';
        };

        return std::all_of( name.begin() + 1, name.end(), valid );
    }
Example #7
0
    bool ParserKeyword::matches(const string_view& name ) const {
        if (!validDeckName(name ))
            return false;

        else if( m_deckNames.count( name.string() ) )
            return true;

        else if (hasMatchRegex()) {
            return boost::regex_match( name.begin(), name.end(), m_matchRegex);
        }

        return false;
    }
Example #8
0
static int ProcessBrackets(string_view const Str, wchar_t const EndMark, brackets& Brackets)
{
	for (auto Iterator = Str.begin(); Iterator != Str.end(); ++Iterator)
	{
		if (*Iterator == L'(')
		{
			if (!Brackets.Bracket)
			{
				Brackets.Bracket = true;
				Brackets.BeginBracket = &*Iterator;
			}

			++Brackets.BracketsCount;
		}
		else if (*Iterator == L')')
		{
			if (!Brackets.BracketsCount)
				return 0;

			--Brackets.BracketsCount;

			if (!Brackets.BracketsCount)
			{
				if (!Brackets.EndBracket)
					Brackets.EndBracket = &*Iterator;
			}
		}
		else if (*Iterator == EndMark && !!Brackets.BeginBracket == !!Brackets.EndBracket)
		{
			if (Brackets.BracketsCount)
				return 0;

			return Iterator - Str.begin() + 1;
		}
	}

	return 0;
};
Example #9
0
int main()
{
    typedef std::string_view    string_view;
    typedef std::u16string_view u16string_view;
    typedef std::u32string_view u32string_view;
    typedef std::wstring_view   wstring_view;

    test(string_view   ());
    test(u16string_view());
    test(u32string_view());
    test(wstring_view  ());
    test(string_view   ( "123"));
    test(wstring_view  (L"123"));
#if TEST_STD_VER >= 11
    test(u16string_view{u"123"});
    test(u32string_view{U"123"});
#endif

#if TEST_STD_VER > 11
    {
    constexpr string_view       sv { "123", 3 };
    constexpr u16string_view u16sv {u"123", 3 };
    constexpr u32string_view u32sv {U"123", 3 };
    constexpr wstring_view     wsv {L"123", 3 };

    static_assert (    sv.begin() !=    sv.end(), "" );
    static_assert ( u16sv.begin() != u16sv.end(), "" );
    static_assert ( u32sv.begin() != u32sv.end(), "" );
    static_assert (   wsv.begin() !=   wsv.end(), "" );

    static_assert (    sv.begin() !=    sv.cend(), "" );
    static_assert ( u16sv.begin() != u16sv.cend(), "" );
    static_assert ( u32sv.begin() != u32sv.cend(), "" );
    static_assert (   wsv.begin() !=   wsv.cend(), "" );
    }
#endif
}
Example #10
0
int main()
{
    typedef std::experimental::string_view    string_view;
    typedef std::experimental::u16string_view u16string_view;
    typedef std::experimental::u32string_view u32string_view;
    typedef std::experimental::wstring_view   wstring_view;

    test(string_view   ());
    test(u16string_view());
    test(u32string_view());
    test(wstring_view  ());
    test(string_view   ( "123"));
    test(wstring_view  (L"123"));
#if __cplusplus >= 201103L
    test(u16string_view{u"123"});
    test(u32string_view{U"123"});
#endif

#if _LIBCPP_STD_VER > 11
    {
    constexpr string_view       sv { "123", 3 };
    constexpr u16string_view u16sv {u"123", 3 };
    constexpr u32string_view u32sv {U"123", 3 };
    constexpr wstring_view     wsv {L"123", 3 };
    
    static_assert (    *sv.begin() ==    sv[0], "" );
    static_assert ( *u16sv.begin() == u16sv[0], "" );
    static_assert ( *u32sv.begin() == u32sv[0], "" );
    static_assert (   *wsv.begin() ==   wsv[0], "" );

    static_assert (    *sv.cbegin() ==    sv[0], "" );
    static_assert ( *u16sv.cbegin() == u16sv[0], "" );
    static_assert ( *u32sv.cbegin() == u32sv[0], "" );
    static_assert (   *wsv.cbegin() ==   wsv[0], "" );
    }
#endif
}
Example #11
0
 inline bool is_dot_dot(const string_view &s)
 { return (s.end()-s.begin()==2) && (*(s.begin())=='.') && (*(s.begin()+1)=='.'); }
Example #12
0
static string ConvertString(const string_view Src)
{
	string Result;
	Result.reserve(Src.size());

	for (auto i = Src.begin(); i != Src.end(); ++i)
	{
		switch (*i)
		{
		case L'\\':
			if (++i == Src.end())
			{
				Result.push_back(L'\\');
				return Result;
			}

			switch (*i)
			{
			case L'\\':
				Result.push_back(L'\\');
				break;

			case L'"':
				Result.push_back(L'"');
				break;

			case L'n':
				Result.push_back(L'\n');
				break;

			case L'r':
				Result.push_back(L'\r');
				break;

			case L'b':
				Result.push_back(L'\b');
				break;

			case L't':
				Result.push_back('\t');
				break;

			default:
				Result.push_back(L'\\');
				--i;
				break;
			}
			break;

		case L'"':
			Result.push_back(L'"');
			if (++i == Src.end())
				return Result;

			if (*i != L'"')
				--i;
			break;

		default:
			Result.push_back(*i);
			break;
		}
	}

	return Result;
}