~ubuntu-branches/ubuntu/karmic/firebird2.1/karmic

« back to all changes in this revision

Viewing changes to src/common/classes/MetaName.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Damyan Ivanov
  • Date: 2008-05-26 23:59:25 UTC
  • Revision ID: james.westby@ubuntu.com-20080526235925-2pnqj6nxpppoeaer
Tags: upstream-2.1.0.17798-0.ds2
ImportĀ upstreamĀ versionĀ 2.1.0.17798-0.ds2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *      PROGRAM:        Client/Server Common Code
 
3
 *      MODULE:         MetaName.cpp
 
4
 *      DESCRIPTION:    metadata name holder
 
5
 *
 
6
 *  The contents of this file are subject to the Initial
 
7
 *  Developer's Public License Version 1.0 (the "License");
 
8
 *  you may not use this file except in compliance with the
 
9
 *  License. You may obtain a copy of the License at
 
10
 *  http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
 
11
 *
 
12
 *  Software distributed under the License is distributed AS IS,
 
13
 *  WITHOUT WARRANTY OF ANY KIND, either express or implied.
 
14
 *  See the License for the specific language governing rights
 
15
 *  and limitations under the License.
 
16
 *
 
17
 *  The Original Code was created by Alexander Peshkov
 
18
 *  for the Firebird Open Source RDBMS project.
 
19
 *
 
20
 *  Copyright (c) 2005 Alexander Peshkov <peshkoff@mail.ru>
 
21
 *  and all contributors signed below.
 
22
 *
 
23
 *  All Rights Reserved.
 
24
 *  Contributor(s): ______________________________________.
 
25
 *
 
26
 *
 
27
 */
 
28
 
 
29
#include "firebird.h"
 
30
 
 
31
#include <stdarg.h>
 
32
 
 
33
#include "../common/classes/MetaName.h"
 
34
 
 
35
namespace Firebird {
 
36
 
 
37
        MetaName& MetaName::assign(const char* s, size_t l)
 
38
        {
 
39
                init();
 
40
                if (s)
 
41
                {
 
42
                        adjustLength(s, l);
 
43
                        count = l;
 
44
                        memcpy(data, s, l);
 
45
                }
 
46
                else {
 
47
                        count = 0;
 
48
                }
 
49
                return *this;
 
50
        }
 
51
 
 
52
        int MetaName::compare(const char* s, size_t l) const 
 
53
        {
 
54
                if (s)
 
55
                {
 
56
                        adjustLength(s, l);
 
57
                        size_t x = length() < l ? length() : l;
 
58
                        int rc = memcmp(c_str(), s, x);
 
59
                        if (rc)
 
60
                        {
 
61
                                return rc;
 
62
                        }
 
63
                }
 
64
                return length() - l;
 
65
        }
 
66
 
 
67
        void MetaName::adjustLength(const char* const s, size_t& l)
 
68
        {
 
69
                fb_assert(s);
 
70
                if (l > MAX_SQL_IDENTIFIER_LEN)
 
71
                {
 
72
                        l = MAX_SQL_IDENTIFIER_LEN;
 
73
                }
 
74
                while (l)
 
75
                {
 
76
                        if (s[l - 1] != ' ')
 
77
                        {
 
78
                                break;
 
79
                        }
 
80
                        --l;
 
81
                }
 
82
        }
 
83
 
 
84
        void MetaName::upper7()
 
85
        {
 
86
                for (char* p = data; *p; p++) 
 
87
                {
 
88
                        *p = UPPER7(*p);
 
89
                }
 
90
        }
 
91
 
 
92
        void MetaName::lower7()
 
93
        {
 
94
                for (char* p = data; *p; p++) 
 
95
                {
 
96
                        *p = LOWWER7(*p);
 
97
                }
 
98
        }
 
99
 
 
100
        void MetaName::printf(const char* format, ...)
 
101
        {
 
102
                init();
 
103
                va_list params;
 
104
                va_start(params, format);
 
105
                int l = VSNPRINTF(data, MAX_SQL_IDENTIFIER_LEN, format, params);
 
106
                if (l < 0 || size_t(l) > MAX_SQL_IDENTIFIER_LEN)
 
107
                {
 
108
                        l = MAX_SQL_IDENTIFIER_LEN;
 
109
                }
 
110
                data[l] = 0;
 
111
                count = l;
 
112
                va_end(params);
 
113
        }
 
114
 
 
115
        char* MetaName::getBuffer(size_t l) 
 
116
        {
 
117
                fb_assert (l < MAX_SQL_IDENTIFIER_SIZE);
 
118
                init();
 
119
                count = l;
 
120
                return data;
 
121
        }
 
122
 
 
123
} // namespace Firebird
 
124