File: resources.cpp

package info (click to toggle)
mysql-connector-c%2B%2B 1.1.0~r814-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 4,388 kB
  • ctags: 3,838
  • sloc: cpp: 39,820; ansic: 2,114; perl: 936; php: 528; xml: 399; sql: 399; sh: 85; makefile: 47
file content (168 lines) | stat: -rw-r--r-- 7,346 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
   Copyright 2007 - 2008 MySQL AB, 2008 - 2010 Sun Microsystems, Inc.  All rights reserved.

   The MySQL Connector/C++ is licensed under the terms of the GPL
   <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most
   MySQL Connectors. There are special exceptions to the terms and
   conditions of the GPL as it is applied to this software, see the
   FLOSS License Exception
   <http://www.mysql.com/about/legal/licensing/foss-exception.html>.
 */

#include <fstream>

#include "resources.h"
#include "../common/stringutils.h"

namespace testsuite
{
namespace resources
{

void CharsetMapping::Init()
{
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("big5"), 2U));

  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("dec8"), 1U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("cp850"), 1U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("hp8"), 1U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("koi8r"), 1U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("latin1"), 1U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("latin2"), 1U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("swe7"), 1U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("ascii"), 1U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("ujis"), 3U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("sjis"), 2U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("hebrew"), 1U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("tis620"), 1U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("euckr"), 2U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("koi8u"), 1U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("gb2312"), 2U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("greek"), 1U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("cp1250"), 1U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("gbk"), 2U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("latin5"), 1U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("armscii8"), 1U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("utf8"), 3U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("ucs2"), 2U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("cp866"), 1U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("keybcs2"), 1U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("macce"), 1U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("macroman"), 1U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("cp852"), 1U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("latin7"), 1U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("cp1251"), 1U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("cp1256"), 1U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("cp1257"), 1U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("binary"), 1U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("geostd8"), 1U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("cp932"), 2U));
  STATIC_CHARSET_TO_NUM_BYTES_MAP.insert(
                                         std::map<String, unsigned int>::value_type(_T("eucjpms"), 3U));
}

const CharsetMapping & CharsetMapping::Instance()
{
  static CharsetMapping instance;
  return instance;
}

bool OpenFile(std::ifstream & fileStream, const String & fileName
              , const char * _possibleLocations[])
{
  fileStream.open(fileName.c_str());

  int i=0;

  while (!fileStream.is_open()
         && _possibleLocations != NULL && _possibleLocations[ i ] != NULL)
  {
    fileStream.clear();
    fileStream.open((String(_possibleLocations[ i ]) + "/" + fileName).c_str());
    ++i;
  }

  return fileStream.is_open();
}

int LoadProperties(const String & fileName, Properties & props
                   , const char * _possibleLocations[])
{
  int counter=0;

  std::ifstream propsFile;

  if (OpenFile(propsFile, fileName, _possibleLocations))
  {
    String line;
    while (getline(propsFile, line))
    {
      StringUtils::trim(line);

      // Not empty line or a comment
      if (!propsFile.eof() && line.size() > 0 && line.c_str()[0] != '#')
      {
        String::size_type pos=line.find_first_of("=");

        if (pos != String::npos && pos > 0)
        {
          String key=line.substr(0, pos);
          String val=line.substr(pos + 1);

          StringUtils::trim( key );
          StringUtils::trim( val );

          props.insert(Properties::value_type(key, val));
          ++counter;
        }

      }
    }

    propsFile.close();
  }
  else
  {
    std::cout << "Unable to open file" << std::endl;
    return -1;
  }

  return counter;
}
}
}