Пример #1
0
        // add an attribute even if an attribute with the same name already exists
        void add_attribute(string name, string value)
        {
            //attribute_node &anode = *m_attributes.emplace(m_attributes.end(), name, value);
            attribute_node anode = new attribute_node(name, value);

            m_attributes.emplace_back(anode);
            anode.name = anode.name.ToLower();  //std::transform(anode.name.begin(), anode.name.end(), anode.name.begin(), [] (char ch) { return std::tolower(uint8_t(ch)); });
        }
Пример #2
0
                // return the integer value of an attribute, or the specified default if not present
                public long_long get_attribute_int(string attribute, long_long defvalue)  //long long get_attribute_int(const char *attribute, long long defvalue) const;
                {
                    attribute_node attr = get_attribute(attribute);

                    if (attr == null)
                    {
                        return(defvalue);
                    }
                    string string_ = attr.value;

                    //std::istringstream stream;
                    //stream.imbue(f_portable_locale);
                    long_long result  = 0; //long long result;
                    bool      success = true;

                    if (string_[0] == '$')
                    {
                        //stream.str(&string[1]);
                        //unsigned long long uvalue;
                        //stream >> std::hex >> uvalue;
                        //result = static_cast<long long>(uvalue);
                        string stream = string_.Substring(1);
                        try { result = Convert.ToInt64(stream, 16); }
                        catch (Exception) { success = false; }
                    }
                    else if ((string_[0] == '0') && ((string_[1] == 'x') || (string_[1] == 'X')))
                    {
                        //stream.str(&string[2]);
                        //unsigned long long uvalue;
                        //stream >> std::hex >> uvalue;
                        //result = static_cast<long long>(uvalue);
                        string stream = string_.Substring(2);
                        try { result = Convert.ToInt64(stream, 16); }
                        catch (Exception) { success = false; }
                    }
                    else if (string_[0] == '#')
                    {
                        //stream.str(&string[1]);
                        //stream >> result;
                        string stream = string_.Substring(1);
                        success = Int64.TryParse(stream, out result);
                    }
                    else
                    {
                        //stream.str(&string[0]);
                        //stream >> result;
                        string stream = string_;
                        success = Int64.TryParse(stream, out result);
                    }

                    return(success ? result : defvalue);  //return stream ? result : defvalue;
                }
Пример #3
0
                // return the format of the given integer attribute
                //int_format get_attribute_int_format(const char *attribute) const;


                // return the float value of an attribute, or the specified default if not present
                //-------------------------------------------------
                //    get_attribute_float - get the float
                //    value of the specified attribute; if not
                //    found, return = the provided default
                //-------------------------------------------------
                public float get_attribute_float(string attribute, float defvalue)
                {
                    attribute_node attr = get_attribute(attribute);

                    if (attr == null)
                    {
                        return(defvalue);
                    }

                    string stream = attr.value;  //std::istringstream stream(attr->value);

                    //stream.imbue(f_portable_locale);
                    //float result;
                    //return (stream >> result) ? result : defvalue;
                    return(Convert.ToSingle(stream));
                }
Пример #4
0
        // return the string value of an attribute, or the specified default if not present
        public string get_attribute_string(string attribute, string defvalue)
        {
            attribute_node attr = get_attribute(attribute);

            return(attr != null?attr.value.c_str() : defvalue);
        }
Пример #5
0
                // return a pointer to the string value of an attribute, or nullptr if not present
                //-------------------------------------------------
                //  get_attribute_string_ptr - get a pointer to
                //  the string value of the specified attribute;
                //  if not found, return = nullptr
                //-------------------------------------------------
                public string get_attribute_string_ptr(string attribute)
                {
                    attribute_node attr = get_attribute(attribute);

                    return(attr != null ? attr.value : null);
                }