Beispiel #1
0
    uuid operator()(CharIterator begin, CharIterator end) const
    {
        typedef typename std::iterator_traits<CharIterator>::value_type char_type;

        // check open brace
        char_type c = get_next_char(begin, end);
        bool has_open_brace = is_open_brace(c);
        char_type open_brace_char = c;
        if (has_open_brace) {
            c = get_next_char(begin, end);
        }

        bool has_dashes = false;

        uuid u;
        int i=0;
        for (uuid::iterator it_byte=u.begin(); it_byte!=u.end(); ++it_byte, ++i) {
            if (it_byte != u.begin()) {
                c = get_next_char(begin, end);
            }
            
            if (i == 4) {
                has_dashes = is_dash(c);
                if (has_dashes) {
                    c = get_next_char(begin, end);
                }
            }
            
            if (has_dashes) {
                if (i == 6 || i == 8 || i == 10) {
                    if (is_dash(c)) {
                        c = get_next_char(begin, end);
                    } else {
                        throw_invalid();
                    }
                }
            }

            *it_byte = get_value(c);

            c = get_next_char(begin, end);
            *it_byte <<= 4;
            *it_byte |= get_value(c);
        }

        // check close brace
        if (has_open_brace) {
            c = get_next_char(begin, end);
            check_close_brace(c, open_brace_char);
        }
        
        return u;
    }
Beispiel #2
0
// Adapted from boost::uuids
cql::cql_uuid_t::cql_uuid_t(const std::string& uuid_string) {
    typedef std::string::value_type char_type;
    std::string::const_iterator begin = uuid_string.begin(),
                                end   = uuid_string.end();
    
    // check open brace
    char_type c = get_next_char(begin, end);
    bool has_open_brace = is_open_brace(c);
    char_type open_brace_char = c;
    if (has_open_brace) {
        c = get_next_char(begin, end);
    }
    
    bool has_dashes = false;
    
    size_t i = 0u;
    for (cql_byte_t* it_byte = _uuid; it_byte != _uuid+_size; ++it_byte, ++i) {
        if (it_byte != _uuid) {
            c = get_next_char(begin, end);
        }
        
        if (i == 4) {
            has_dashes = is_dash(c);
            if (has_dashes) {
                c = get_next_char(begin, end);
            }
        }
        
        if (has_dashes) {
            if (i == 6 || i == 8 || i == 10) {
                if (is_dash(c)) {
                    c = get_next_char(begin, end);
                } else {
                    throw std::invalid_argument("String to make UUID from has a misplaced dash");
                }
            }
        }
        
        *it_byte = get_value(c);
        
        c = get_next_char(begin, end);
        *it_byte <<= 4;
        *it_byte |= get_value(c);
    }
    
    // check close brace
    if (has_open_brace) {
        c = get_next_char(begin, end);
        check_close_brace(c, open_brace_char);
    }
}