Subversion Repositories autosfx

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 daniel-mar 1
/* ***** BEGIN LICENSE BLOCK *****
2
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3
 *
4
 * The contents of this file are subject to the Mozilla Public License Version
5
 * 1.1 (the "License"); you may not use this file except in compliance with
6
 * the License. You may obtain a copy of the License at
7
 * http://www.mozilla.org/MPL/
8
 *
9
 * Software distributed under the License is distributed on an "AS IS" basis,
10
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11
 * for the specific language governing rights and limitations under the
12
 * License.
13
 *
14
 * The Original Code is for Open Layer for Unicode (opencow).
15
 *
16
 * The Initial Developer of the Original Code is Brodie Thiesfield.
17
 * Portions created by the Initial Developer are Copyright (C) 2004
18
 * the Initial Developer. All Rights Reserved.
19
 *
20
 * Contributor(s):
21
 *
22
 * Alternatively, the contents of this file may be used under the terms of
23
 * either the GNU General Public License Version 2 or later (the "GPL"), or
24
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
25
 * in which case the provisions of the GPL or the LGPL are applicable instead
26
 * of those above. If you wish to allow use of your version of this file only
27
 * under the terms of either the GPL or the LGPL, and not to allow others to
28
 * use your version of this file under the terms of the MPL, indicate your
29
 * decision by deleting the provisions above and replace them with the notice
30
 * and other provisions required by the GPL or the LGPL. If you do not delete
31
 * the provisions above, a recipient may use your version of this file under
32
 * the terms of any one of the MPL, the GPL or the LGPL.
33
 *
34
 * ***** END LICENSE BLOCK ***** */
35
/************************************************************************
36
 Copyright (C) 2009, 2010  by Russell J. Peters, Roger Aelbrecht
37
 
38
   This file is part of TZipMaster Version 1.9.
39
 
40
    TZipMaster is free software: you can redistribute it and/or modify
41
    it under the terms of the GNU Lesser General Public License as published by
42
    the Free Software Foundation, either version 3 of the License, or
43
    (at your option) any later version.
44
 
45
    TZipMaster is distributed in the hope that it will be useful,
46
    but WITHOUT ANY WARRANTY; without even the implied warranty of
47
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
48
    GNU Lesser General Public License for more details.
49
 
50
    You should have received a copy of the GNU Lesser General Public License
51
    along with TZipMaster.  If not, see <http://www.gnu.org/licenses/>.
52
 
53
    contact: problems@delphizip.org (include ZipMaster in the subject).
54
    updates: http://www.delphizip.org
55
    DelphiZip maillist subscribe at http://www.freelists.org/list/delphizip
56
************************************************************************/
57
 
58
#ifndef MbcsBufferH
59
#define MbcsBufferH
60
 
61
#include <stdlib.h>
62
#include <errno.h>
63
 
64
#define ARRAY_SIZE(x)   (sizeof(x)/sizeof((x)[0]))
65
 
66
 
67
// ----------------------------------------------------------------------------
68
// UNICODE -> MBCS conversion and general buffer
69
 
70
class CMbcsBuffer
71
{
72
public:
73
    CMbcsBuffer()
74
        : mBuffer(mStackBuffer),
75
          mBufferSize(sizeof(mStackBuffer)),
76
          mLength(0)
77
    {
78
        mStackBuffer[0] = '\0';
79
    }
80
 
81
    ~CMbcsBuffer()
82
    {
83
        if (IsBufferAllocated())
84
            ::free(mBuffer);
85
    }
86
 
87
    bool SetCapacity(int aMinCapacity);
88
 
89
    // if the source string is NULL then we will return NULL, regardless of the setting
90
    // for aMinCapacity. If you want a resizable buffer then use SetCapacity() instead.
91
    bool FromUnicode(LPCWSTR aString = 0, int aStringLen = -1, int aMinCapacity = 0);
92
 
93
//    int ToUnicode(LPWSTR lpszDst, int MaxLen);
94
 
95
    void SetNull()
96
    {
97
        if (IsBufferAllocated())
98
            ::free(mBuffer);
99
        mBuffer     = 0;
100
        mBufferSize = 0;
101
        mLength     = 0;
102
    }
103
 
104
    bool IsBufferAllocated() const { return (mBuffer && mBuffer != mStackBuffer); }
105
 
106
    char * get()            { return mBuffer; }
107
    operator LPSTR()        { return mBuffer; }
108
    int BufferSize() const  { return mBufferSize; }
109
    int Length() const      { return mLength; }
110
 
111
private:
112
    char    mStackBuffer[256];
113
    char *  mBuffer;
114
    int     mBufferSize;
115
    int     mLength;
116
};
117
 
118
#endif // INCLUDED_MbcsBuffer