Example #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;
    }
Example #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);
    }
}
Example #3
0
void parse_args(int argc, char *argv[]) {
  char *arg;
  int i = 1;
  int na = 1;  /* 1 = in, 2 = out, 3 = xdim, 4 = ydim */

  while (i < argc) {
    arg = argv[i];
    if (!strcmp(arg, "-h")) {
      usage(argv[0]);
      exit(0);
    } else if (!strcmp(arg, "-q")) {
      jpg_quality = atoi(argv[++i]);
    } else if (!strcmp(arg, "-x")) {
      shortFormat = 1;
    } else {
      switch (na) {
      case 1: 
	infile = arg;
	outfile = arg;
	na++;
	break;
      case 2:
	outfile = arg;
	na++;
	break;
      case 3:
	sizeonly = 0; /* we actually want rescaling */
	xscale = is_perc(arg);
	yscale = xscale;
	if (xscale == 0.0) {
	  if (is_dash(arg)) {
	    x = 0;
	  } else {
	    x = atoi(arg);
	    y = x;
	  }
	}
	na++;
	break;
      case 4:
	yscale = is_perc(arg);
	if (yscale == 0.0) {
	  if (is_dash(arg)) {
	    y = 0;
	  } else {
	    y = atoi(arg);
	  }
	}
	na++;
	break;
      }
    }
    i++;
  }
  /*
  printf("x = %d\n", x);
  printf("xscale = %f\n", xscale);
  printf("y = %d\n", y);
  printf("yscale = %f\n", yscale);
  printf("size = %d\n", sizeonly);
  */
}