Atlas-C++
Utility.h
Go to the documentation of this file.
1 // This file may be redistributed and modified under the terms of the
2 // GNU Lesser General Public License (See COPYING for details).
3 // Copyright (C) 2000 Stefanus Du Toit, Michael Day
4 
5 // $Id$
6 
7 #ifndef ATLAS_CODECS_UTILITY_H
8 #define ATLAS_CODECS_UTILITY_H
9 
20 #include <cstdio>
21 #include <string>
22 
23 namespace Atlas { namespace Codecs {
24 
26 inline const std::string charToHex(char c)
27 {
28  char hex[3];
29 #ifdef _WIN32
30  _snprintf(hex, 3, "%x", c);
31 #else
32  snprintf(hex, 3, "%x", c);
33 #endif
34  return hex;
35 }
36 
38 inline char hexToChar(const std::string& hex)
39 {
40  int c;
41  if (sscanf(hex.c_str(), "%x", &c) == 1) {
42  return (char) c;
43  } else {
44  return (char) 0;
45  }
46 }
47 
48 const std::string hexEncodeWithPrefix(const std::string& prefix,
49  const std::string& special,
50  const std::string& message);
51 
52 const std::string hexDecodeWithPrefix(const std::string& prefix,
53  const std::string& message);
54 
55 } } // namespace Atlas::Codecs
56 
57 #endif // ATLAS_CODECS_UTILITY_H
const std::string charToHex(char c)
Convert an ASCII char to its hexadecimal value.
Definition: Utility.h:26
char hexToChar(const std::string &hex)
Convert a string with a hexadecimal value (2 characters) to an ASCII char.
Definition: Utility.h:38
The Atlas namespace.
Definition: Bridge.h:20

Copyright 2000-2004 the respective authors.

This document can be licensed under the terms of the GNU Free Documentation License or the GNU General Public License and may be freely distributed under the terms given by one of these licenses.