ReFRACtor
util.py
Go to the documentation of this file.
1 from refractor import framework as rf
2 from string import Formatter
3 
4 def as_vector_string(string_vals):
5  "Convert a list of strings into a C++ vector of strings"
6 
7  vec_str = rf.vector_string()
8  for str_val in string_vals:
9 
10  if isinstance(str_val, bytes):
11  str_val = str_val.decode("UTF-8")
12  elif not isinstance(str_val, str):
13  raise TypeError("Cannot add incompatible type to vector_string: %s" % str_val)
14 
15  vec_str.push_back(str_val)
16  return vec_str
17 
18 class ExtendedFormatter(Formatter):
19  """An extended format string formatter
20 
21  Formatter with extended conversion symbol
22  """
23  def convert_field(self, value, conversion):
24  """ Extend conversion symbol
25  Following additional symbol has been added
26  * l: convert to string and low case
27  * u: convert to string and up case
28 
29  default are:
30  * s: convert with str()
31  * r: convert with repr()
32  * a: convert with ascii()
33  """
34 
35  if conversion == "u":
36  return str(value).upper()
37  elif conversion == "l":
38  return str(value).lower()
39  # Do the default conversion or raise error if no matching conversion found
40  super(ExtendedFormatter, self).convert_field(value, conversion)
41 
42  # return for None case
43  return value
44 
def as_vector_string(string_vals)
Definition: util.py:4
def convert_field(self, value, conversion)
Definition: util.py:23

Copyright © 2017, California Institute of Technology.
ALL RIGHTS RESERVED.
U.S. Government Sponsorship acknowledged.
Generated Fri Aug 24 2018 15:44:10