Esempio n. 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());
    }
}
Esempio n. 2
0
void
pvt::debugmsg_ (string_view message)
{
    recursive_lock_guard lock (pvt::imageio_mutex);
    if (print_debug) {
        std::cerr << "OIIO DEBUG: " << message 
                  << (message.back() == '\n' ? "" : "\n");
    }
}
Esempio n. 3
0
static lng_line_type parse_lng_line(const string_view str, bool ParseLabels, string_view& Label, string_view& Data)
{
	Label = {};
	Data = {};

	//-- "Text"
	if (starts_with(str, L'"'))
	{
		Data = str.substr(1, str.size() - (ends_with(str, L'"')? 2 : 1));
		return lng_line_type::text;
	}

	//-- //[Label]
	if (ParseLabels)
	{
		const auto Prefix = L"//["sv, Suffix = L"]"sv;
		if (starts_with(str, Prefix) && ends_with(str, Suffix))
		{
			Label = str.substr(Prefix.size(), str.size() - Prefix.size() - Suffix.size());
			return lng_line_type::label;
		}
	}

	//-- MLabel="Text"
	if (ParseLabels && !str.empty() && str.back() == L'"')
	{
		const auto eq_pos = str.find(L'=');
		if (eq_pos != str.npos && std::iswalpha(str[0]))
		{
			const auto Value = trim(str.substr(eq_pos + 1));

			if (starts_with(Value, L'"'))
			{
				Label = trim(str.substr(0, eq_pos));
				Data = Value.substr(1, Value.size() - 2);
				return lng_line_type::both;
			}
		}
	}

	return lng_line_type::none;
}
Esempio n. 4
0
static void parse_lng_line(const string_view str, string& label, string& data, bool& have_data)
{
	have_data = false;

	//-- //[Label]
	if (starts_with(str, L"//["sv) && ends_with(str, L"]"sv))
	{
		const auto LabelView = str.substr(3, str.size() - 3 - 1);
		//-- //[Label=0]
		assign(label, LabelView.substr(0, LabelView.find(L'=')));
		return;
	}

	//-- "Text"
	if (starts_with(str, L'"'))
	{
		have_data = true;
		assign(data, str.substr(1));
		if (!data.empty() && data.back() == L'"')
			data.pop_back();
		return;
	}

	//-- MLabel="Text"
	if (!str.empty() && str.back() == L'"')
	{
		const auto eq_pos = str.find(L'=');
		if (eq_pos != string::npos && InRange(L'A', upper(str[0]), L'Z'))
		{
			assign(data, trim(str.substr(eq_pos + 1)));
			if (data.size() > 1 && data[0] == L'"')
			{
				assign(label, trim(str.substr(0, eq_pos)));
				have_data = true;
				data.pop_back();
				data.erase(0, 1);
			}
		}
	}
}
Esempio n. 5
0
// Add the attribute -- figure out the type
void
parse_param(string_view paramname, string_view val, ImageSpec& spec)
{
    TypeDesc type;  // start out unknown

    // If the param string starts with a type name, that's what it is
    if (size_t typeportion = type.fromstring(paramname)) {
        paramname.remove_prefix(typeportion);
        Strutil::skip_whitespace(paramname);
    }
    // If the value string starts with a type name, that's what it is
    else if (size_t typeportion = type.fromstring(val)) {
        val.remove_prefix(typeportion);
        Strutil::skip_whitespace(val);
    }

    if (type.basetype == TypeDesc::UNKNOWN) {
        // If we didn't find a type name, try to guess
        if (val.size() >= 2 && val.front() == '\"' && val.back() == '\"') {
            // Surrounded by quotes? it's a string (strip off the quotes)
            val.remove_prefix(1);
            val.remove_suffix(1);
            type = TypeDesc::TypeString;
        } else if (Strutil::string_is<int>(val)) {
            // Looks like an int, is an int
            type = TypeDesc::TypeInt;
        } else if (Strutil::string_is<float>(val)) {
            // Looks like a float, is a float
            type = TypeDesc::TypeFloat;
        } else {
            // Everything else is assumed a string
            type = TypeDesc::TypeString;
        }
    }

    // Read the values and set the attribute
    int n = type.numelements() * type.aggregate;
    if (type.basetype == TypeDesc::INT) {
        std::vector<int> values(n);
        for (int i = 0; i < n; ++i) {
            Strutil::parse_int(val, values[i]);
            Strutil::parse_char(val, ',');  // optional
        }
        if (n > 0)
            spec.attribute(paramname, type, &values[0]);
    }
    if (type.basetype == TypeDesc::FLOAT) {
        std::vector<float> values(n);
        for (int i = 0; i < n; ++i) {
            Strutil::parse_float(val, values[i]);
            Strutil::parse_char(val, ',');  // optional
        }
        if (n > 0)
            spec.attribute(paramname, type, &values[0]);
    } else if (type.basetype == TypeDesc::STRING) {
        std::vector<ustring> values(n);
        for (int i = 0; i < n; ++i) {
            string_view v;
            Strutil::parse_string(val, v);
            Strutil::parse_char(val, ',');  // optional
            values[i] = v;
        }
        if (n > 0)
            spec.attribute(paramname, type, &values[0]);
    }
}
Esempio n. 6
0
 bool RawRecord::isTerminatedRecordString( const string_view& str ) {
     return str.back() == RawConsts::slash;
 }