Beispiel #1
0
	static bool shouldConsiderUnaryLiteral(string_view& stream, Location& pos)
	{
		// check the previous token
		bool should = (prevType != TokenType::Invalid && prevID == pos.fileID && (
			prevType != TokenType::RParen &&
			prevType != TokenType::RSquare &&
			prevType != TokenType::Identifier &&
			prevType != TokenType::Number &&
			prevType != TokenType::Dollar &&
			prevType != TokenType::StringLiteral
		));

		if(!should) return false;

		// check if the current char is a + or -
		if(stream.length() == 0) return false;
		if(stream[0] != '+' && stream[0] != '-') return false;

		// check if there's only spaces between this and the number itself
		for(size_t i = 1; i < stream.length(); i++)
		{
			if(isdigit(stream[i])) return true;
			else if(stream[i] != ' ') return false;
		}

		return false;
	}
Beispiel #2
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());
    }
}
	allocation_slot stack_allocator::copy_string(string_view str)
	{
		int const ret = int(m_storage.size());
		m_storage.resize(ret + numeric_cast<int>(str.size()) + 1);
		std::memcpy(&m_storage[ret], str.data(), str.size());
		m_storage[ret + int(str.length())] = '\0';
		return allocation_slot(ret);
	}
Beispiel #4
0
	static bool compare(const string_view& str, char const (&literal)[N])
	{
		if(str.length() != N - 1) return false;
		for(size_t i = 0; i < N - 1; i++)
			if(str[i] != literal[i]) return false;

		return true;
	}
Beispiel #5
0
    bool ParserKeyword::validNameStart( const string_view& name) {
        if (name.length() > ParserConst::maxKeywordLength)
            return false;

        if (!isalpha(name[0]))
            return false;

        return true;
    }
size_t
TypeDesc::fromstring(string_view typestring)
{
    *this            = TypeDesc::UNKNOWN;
    string_view orig = typestring;
    if (typestring.empty()) {
        return 0;
    }

    // The first "word" should be a type name.
    string_view type = Strutil::parse_identifier(typestring);

    // Check the scalar types in our table above
    TypeDesc t;
    for (int i = 0; i < LASTBASE; ++i) {
        if (type == basetype_name[i]) {
            t.basetype = i;
            break;
        }
    }

    // Some special case names for aggregates
    if (t.basetype != UNKNOWN) {
        // already solved
    } else if (type == "color")
        t = TypeColor;
    else if (type == "point")
        t = TypePoint;
    else if (type == "vector")
        t = TypeVector;
    else if (type == "normal")
        t = TypeNormal;
    else if (type == "matrix33")
        t = TypeMatrix33;
    else if (type == "matrix" || type == "matrix44")
        t = TypeMatrix44;
    else if (type == "timecode")
        t = TypeTimeCode;
    else if (type == "rational")
        t = TypeRational;
    else {
        return 0;  // unknown
    }

    // Is there an array length following the type name?
    if (Strutil::parse_char(typestring, '[')) {
        int arraylen = -1;
        Strutil::parse_int(typestring, arraylen);
        if (!Strutil::parse_char(typestring, ']'))
            return 0;  // malformed
        t.arraylen = arraylen;
    }

    *this = t;
    return orig.length() - typestring.length();
}
path_match_result path_match(string_view input, string_view& match_contents)
{
    if (input.length() < 2)
        return path_match_result::invalid;
    
    match_result result;
    token_kind kind;
    std::size_t length;
    
    switch (input.at(0))
    {
    case '.':
        result = match_simple_string(input.data() + 1, input.data() + input.size(), kind, length);
        if (result == match_result::complete)
        {
            match_contents = input.substr(0, length + 1);
            return path_match_result::simple_object;
        }
        else
        {
            return path_match_result::invalid;
        }
    case '[':
        result = attempt_match(input.data() + 1, input.data() + input.length(), kind, length);
        if (result == match_result::complete)
        {
            if (input.length() == length + 1 || input.at(1 + length) != ']')
                return path_match_result::invalid;
            if (kind != token_kind::string && kind != token_kind::number)
                return path_match_result::invalid;
            
            match_contents = input.substr(0, length + 2);
            return path_match_result::brace;
        }
        else
        {
            return path_match_result::invalid;
        }
    default:
        return path_match_result::invalid;
    }
}
Beispiel #8
0
    int reload(lua_State* L, const Data& chunk, const string_view& name)
    {
        lua_getglobal(L, "package");
        lua_pushliteral(L, "loaded");
        lua_rawget(L, -2);

        R_ASSERT(lua_istable(L, -1), "Missing control table 'package.loaded'");

        lua_pushlstring(L, name.data(), name.length());
        lua_pushnil(L);
        lua_rawset(L, -3);
        lua_pop(L, 2);
        return load(L, chunk, name.data(), true);
    }
Beispiel #9
0
wstring
MBCSToWCS(string_view sv, unsigned cp)
{
	return sv.length() != 0 ? MBCSToWCS(CheckNonnegativeScalar<int>(
		sv.length()), sv.data(), cp) : wstring();
}
Beispiel #10
0
string
MBCSToMBCS(string_view sv, unsigned cp_src, unsigned cp_dst)
{
	return sv.length() != 0 ? MBCSToMBCS(CheckNonnegativeScalar<int>(
		sv.length()), sv.data(), cp_src, cp_dst) : string();
}