This repository has been archived by the owner on Jun 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ConnectionString.cpp
68 lines (58 loc) · 1.75 KB
/
ConnectionString.cpp
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
/*!
* \brief The file contains connection string wrapper implementation
* \author \verbatim
Created by: Alexander Egorov
\endverbatim
* \date \verbatim
Creation date: 2010-04-11
\endverbatim
* Copyright 2008-2012 Alexander Egorov <egoroff@gmail.com> (http://www.egoroff.spb.ru)
*/
#include "StdAfx.h"
#include <algorithm>
#include "ConnectionString.h"
const char* kCharsetPattern = "CLIENTCHARSET=";
ConnectionString::ConnectionString(const char* pRawString)
: cnString_(pRawString)
, containsCharset_(false)
{}
ConnectionString::~ConnectionString(void)
{}
void ConnectionString::Parse()
{
std::string::size_type ixQ = cnString_.find("?");
if (ixQ == std::string::npos) {
oleDBString_ = cnString_;
return;
}
oleDBString_ = cnString_.substr(0, ixQ);
std::transform(cnString_.begin(), cnString_.end(), cnString_.begin(), toupper);
std::string::size_type ix = cnString_.find(kCharsetPattern);
containsCharset_ = ix != std::string::npos;
if (containsCharset_) {
charset_ = cnString_.substr(ix + strlen(kCharsetPattern));
}
}
bool ConnectionString::ContainsCharset() const
{
return containsCharset_;
}
const std::string& ConnectionString::GetCharset() const
{
return charset_;
}
void ConnectionString::CopyCharset(
char* pDestination,
std::string::size_type destLength) const
{
charset_._Copy_s(pDestination, destLength, charset_.length());
pDestination[charset_.length()] = 0;
}
size_t ConnectionString::CharsetLength() const
{
return charset_.length() + 1;
}
const std::string& ConnectionString::GetOleDBString() const
{
return oleDBString_;
}