Changeset 373


Ignore:
Timestamp:
Jun 19, 2007, 11:53:16 PM (13 years ago)
Author:
Peter Johansson
Message:

adding function transforming decimal int to hexadecimal refs #200

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/utility.cc

    r313 r373  
    7979
    8080
     81  std::string hex(int x, u_int width)
     82  {
     83    std::stringstream ss;
     84    ss << std::hex << x;
     85    if (!width)
     86      return ss.str();
     87    if (ss.str().size()<width)
     88      return std::string(width-ss.str().size(), '0') + ss.str();
     89    return ss.str().substr(0, width);
     90  }
     91
     92
    8193  std::string htrim(std::string str)
    8294  {
  • trunk/lib/utility.h

    r371 r373  
    6363  ///
    6464  std::string getenv(const std::string& var);
     65
     66  ///
     67  /// If @a width is set, size is forced to length @a width. This
     68  /// implies, e.g., that hex(15,2) and hex(17,1) return "0F" and "1",
     69  /// respectively.
     70  ///
     71  /// @return x in hexadecimal base
     72  ///
     73  std::string hex(int x, u_int width=0);
    6574
    6675  ///
  • trunk/test/Makefile.am

    r329 r373  
    2222# 02111-1307, USA.
    2323
    24 check_PROGRAMS = gnuplot_pipe parser trac
     24check_PROGRAMS = gnuplot_pipe parser trac utility
    2525
    2626TESTS = $(check_PROGRAMS)
     
    3737parser_SOURCES = parser.cc
    3838trac_SOURCES = trac.cc
     39utility_SOURCES = utility.cc
    3940
    4041check_repo_status.sh: check_repo_status.sh.in Makefile.am
Note: See TracChangeset for help on using the changeset viewer.