1ed2f6d3bSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3ed2f6d3bSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4ed2f6d3bSAndrew Rist * or more contributor license agreements. See the NOTICE file
5ed2f6d3bSAndrew Rist * distributed with this work for additional information
6ed2f6d3bSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7ed2f6d3bSAndrew Rist * to you under the Apache License, Version 2.0 (the
8ed2f6d3bSAndrew Rist * "License"); you may not use this file except in compliance
9ed2f6d3bSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11ed2f6d3bSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13ed2f6d3bSAndrew Rist * Unless required by applicable law or agreed to in writing,
14ed2f6d3bSAndrew Rist * software distributed under the License is distributed on an
15ed2f6d3bSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ed2f6d3bSAndrew Rist * KIND, either express or implied. See the License for the
17ed2f6d3bSAndrew Rist * specific language governing permissions and limitations
18ed2f6d3bSAndrew Rist * under the License.
19cdf0e10cSrcweir *
20ed2f6d3bSAndrew Rist *************************************************************/
21ed2f6d3bSAndrew Rist
22ed2f6d3bSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #ifndef UTILITIES_HXX_INCLUDED
25cdf0e10cSrcweir #define UTILITIES_HXX_INCLUDED
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <malloc.h>
28cdf0e10cSrcweir #if defined _MSC_VER
29cdf0e10cSrcweir #pragma warning(push, 1)
30cdf0e10cSrcweir #endif
31cdf0e10cSrcweir #ifndef OS2
32cdf0e10cSrcweir #include <windows.h>
33cdf0e10cSrcweir #endif
34cdf0e10cSrcweir #if defined _MSC_VER
35cdf0e10cSrcweir #pragma warning(pop)
36cdf0e10cSrcweir #endif
37cdf0e10cSrcweir #include <stdio.h>
38cdf0e10cSrcweir #include <fcntl.h>
39cdf0e10cSrcweir #include <io.h>
40cdf0e10cSrcweir #include "internal/types.hxx"
41cdf0e10cSrcweir
42cdf0e10cSrcweir #include <string>
43781fd7caSPedro Giffuni #ifndef OS2
44cdf0e10cSrcweir #define STRSAFE_NO_DEPRECATE
45cdf0e10cSrcweir #include <strsafe.h>
46781fd7caSPedro Giffuni #endif
47cdf0e10cSrcweir
48cdf0e10cSrcweir //---------------------------------
49cdf0e10cSrcweir /** Convert a string to a wstring
50cdf0e10cSrcweir using CP_ACP
51cdf0e10cSrcweir */
52cdf0e10cSrcweir std::wstring StringToWString(const std::string& String);
53cdf0e10cSrcweir
54cdf0e10cSrcweir //---------------------------------
55cdf0e10cSrcweir /** Convert a wstring to a string
56cdf0e10cSrcweir using CP_ACP
57cdf0e10cSrcweir */
58cdf0e10cSrcweir std::string WStringToString(const std::wstring& String);
59cdf0e10cSrcweir
60cdf0e10cSrcweir //---------------------------------
61cdf0e10cSrcweir /** Retrieve a string from the
62cdf0e10cSrcweir resources of this module
63cdf0e10cSrcweir */
64cdf0e10cSrcweir std::wstring GetResString(int ResId);
65cdf0e10cSrcweir
66cdf0e10cSrcweir //---------------------------------
67cdf0e10cSrcweir /** Returns whether we are running
68cdf0e10cSrcweir on Windows XP or not
69cdf0e10cSrcweir */
70cdf0e10cSrcweir bool is_windows_xp_or_above();
71cdf0e10cSrcweir
72cdf0e10cSrcweir //---------------------------------
73cdf0e10cSrcweir /** helper function to judge if the string is only has spaces.
74cdf0e10cSrcweir @returns
75cdf0e10cSrcweir <TRUE>if the provided string contains only but at least one space
76cdf0e10cSrcweir character else <FALSE/>.
77cdf0e10cSrcweir */
78cdf0e10cSrcweir bool HasOnlySpaces(const std::wstring& String);
79cdf0e10cSrcweir
80cdf0e10cSrcweir /** convert LocaleSet pair into Windows LCID identifier.
81cdf0e10cSrcweir @returns
82cdf0e10cSrcweir Windows Locale Identifier corresponding to input LocaleSet.
83cdf0e10cSrcweir */
84cdf0e10cSrcweir
85cdf0e10cSrcweir //---------------------------------
86cdf0e10cSrcweir /** Convert a long path name using Windows api call GetShortPathName
87cdf0e10cSrcweir */
88cdf0e10cSrcweir std::wstring getShortPathName( const std::wstring& aLongName );
89cdf0e10cSrcweir
90cdf0e10cSrcweir
91cdf0e10cSrcweir #ifndef OS2
92cdf0e10cSrcweir LCID LocaleSetToLCID( const LocaleSet_t & Locale );
93cdf0e10cSrcweir #endif
94cdf0e10cSrcweir
95781fd7caSPedro Giffuni #ifdef OS2
96781fd7caSPedro Giffuni typedef const char *LPCSTR;
97781fd7caSPedro Giffuni #endif
98781fd7caSPedro Giffuni
99cdf0e10cSrcweir //----------------------------------------------------------
100cdf0e10cSrcweir #ifdef DEBUG
OutputDebugStringFormat(LPCSTR pFormat,...)101cdf0e10cSrcweir inline void OutputDebugStringFormat( LPCSTR pFormat, ... )
102cdf0e10cSrcweir {
103*3e91741bSYuri Dario #ifndef OS2
104cdf0e10cSrcweir CHAR buffer[1024];
105cdf0e10cSrcweir va_list args;
106cdf0e10cSrcweir
107cdf0e10cSrcweir va_start( args, pFormat );
108cdf0e10cSrcweir StringCchVPrintfA( buffer, sizeof(buffer), pFormat, args );
109cdf0e10cSrcweir OutputDebugStringA( buffer );
110781fd7caSPedro Giffuni #endif
111cdf0e10cSrcweir }
112cdf0e10cSrcweir #else
OutputDebugStringFormat(LPCSTR,...)113cdf0e10cSrcweir static inline void OutputDebugStringFormat( LPCSTR, ... )
114cdf0e10cSrcweir {
115cdf0e10cSrcweir }
116cdf0e10cSrcweir #endif
117cdf0e10cSrcweir //----------------------------------------------------------
118cdf0e10cSrcweir
119cdf0e10cSrcweir
120cdf0e10cSrcweir #endif
121