Avoid potential negative array index access to cached text.
[LibreOffice.git] / shell / inc / utilities.hxx
blob1941d85e658a1816631d60b332029672f924daa8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SHELL_INC_INTERNAL_UTILITIES_HXX
21 #define INCLUDED_SHELL_INC_INTERNAL_UTILITIES_HXX
23 #include <malloc.h>
25 #if !defined WIN32_LEAN_AND_MEAN
26 #define WIN32_LEAN_AND_MEAN
27 #endif
28 #include <windows.h>
30 #include <stdio.h>
31 #include <fcntl.h>
32 #include <io.h>
33 #include "types.hxx"
35 #include <string>
36 #define STRSAFE_NO_DEPRECATE
37 #include <strsafe.h>
39 /** Convert a string to a wstring
40 using CP_ACP
42 std::wstring StringToWString(const std::string& String);
44 /** Convert a wstring to a string
45 using CP_ACP
47 std::string WStringToString(const std::wstring& String);
49 /** Convert a string to a wstring
50 using CP_UTF8
52 std::wstring UTF8ToWString(const std::string& String);
54 /** Retrieve a string from the
55 resources of this module
57 std::wstring GetResString(int ResId);
59 /** helper function to judge if the string is only has spaces.
60 @returns
61 <TRUE>if the provided string contains only but at least one space
62 character else <FALSE/>.
64 bool HasOnlySpaces(const std::wstring& String);
66 /** convert LocaleSet pair into Windows LCID identifier.
67 @returns
68 Windows Locale Identifier corresponding to input LocaleSet.
71 /** Convert a long path name using Windows api call GetShortPathName
73 std::wstring getShortPathName(const std::wstring& aLongName);
75 LCID LocaleSetToLCID(const LocaleSet_t& Locale);
77 #ifdef DEBUG
78 inline void OutputDebugStringFormatW(LPCWSTR pFormat, ...)
80 WCHAR buffer[1024];
81 va_list args;
83 va_start(args, pFormat);
84 StringCchVPrintfW(buffer, sizeof(buffer) / sizeof(*buffer), pFormat, args);
85 va_end(args);
86 OutputDebugStringW(buffer);
88 #else
89 static inline void OutputDebugStringFormatW(LPCWSTR, ...) {}
90 #endif
92 #endif
94 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */