strnumtest.cc revision 2
113516Sgabeblack@google.com/*
213516Sgabeblack@google.com * Copyright (c) 2003 The Regents of The University of Michigan
313516Sgabeblack@google.com * All rights reserved.
413516Sgabeblack@google.com *
513516Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
613516Sgabeblack@google.com * modification, are permitted provided that the following conditions are
713516Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
813516Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
913516Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
1013516Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1113516Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1213516Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1313516Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1413516Sgabeblack@google.com * this software without specific prior written permission.
1513516Sgabeblack@google.com *
1613516Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1713516Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1813516Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1913516Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2013586Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2113586Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2213586Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2313516Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2413516Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2513516Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2613516Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2713516Sgabeblack@google.com */
2813516Sgabeblack@google.com
2913516Sgabeblack@google.com#include <iostream.h>
3013516Sgabeblack@google.com
3113516Sgabeblack@google.com#include <string>
3213516Sgabeblack@google.com#include <vector>
3313516Sgabeblack@google.com
3413516Sgabeblack@google.com#include "str.hh"
3513516Sgabeblack@google.com
3613516Sgabeblack@google.comint
3713516Sgabeblack@google.commain(int argc, char *argv[])
3813516Sgabeblack@google.com{
3913516Sgabeblack@google.com  if (argc != 2) {
4013516Sgabeblack@google.com    cout << "Usage: " << argv[0] << " <number>\n";
4113516Sgabeblack@google.com    exit(1);
4213516Sgabeblack@google.com  }
4313516Sgabeblack@google.com
4413519Sgabeblack@google.com  string s = argv[1];
4513519Sgabeblack@google.com
4613516Sgabeblack@google.com#define OUTVAL(valtype, type) do { \
4713516Sgabeblack@google.com  valtype value; \
4813516Sgabeblack@google.com  cout << "TYPE = " #valtype "\n"; \
4913516Sgabeblack@google.com  if (to_number(s, value)) { \
5013516Sgabeblack@google.com    cout << "Number(" << s << ") = " << dec \
5113516Sgabeblack@google.com      << (unsigned long long)(unsigned type)value << "\n" \
52      << "Number(" << s << ") = " << dec \
53      << (signed long long)(signed type)value << "\n" \
54      << "Number(" << s << ") = 0x" << hex \
55      << (unsigned long long)(unsigned type)value << "\n" \
56      << "Number(" << s << ") = 0" << oct \
57      << (unsigned long long)(unsigned type)value << "\n\n"; \
58  } else \
59    cout << "Number(" << s << ") is invalid\n\n"; \
60  } while (0)
61
62  OUTVAL(signed long long, long long);
63  OUTVAL(unsigned long long, long long);
64  OUTVAL(signed long, long);
65  OUTVAL(unsigned long, long);
66  OUTVAL(signed int, int);
67  OUTVAL(unsigned int, int);
68  OUTVAL(signed short, short);
69  OUTVAL(unsigned short, short);
70  OUTVAL(signed char, char);
71  OUTVAL(unsigned char, char);
72
73  return 0;
74}
75