PageRenderTime 24ms CodeModel.GetById 14ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/thirdparty/breakpad/common/windows/guid_string.cc

http://github.com/tomahawk-player/tomahawk
C++ | 76 lines | 29 code | 12 blank | 35 comment | 0 complexity | d5702ee9dc9112d7132c8f83187b55ab MD5 | raw file
 1// Copyright (c) 2006, Google Inc.
 2// All rights reserved.
 3//
 4// Redistribution and use in source and binary forms, with or without
 5// modification, are permitted provided that the following conditions are
 6// met:
 7//
 8//     * Redistributions of source code must retain the above copyright
 9// notice, this list of conditions and the following disclaimer.
10//     * Redistributions in binary form must reproduce the above
11// copyright notice, this list of conditions and the following disclaimer
12// in the documentation and/or other materials provided with the
13// distribution.
14//     * Neither the name of Google Inc. nor the names of its
15// contributors may be used to endorse or promote products derived from
16// this software without specific prior written permission.
17//
18// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30// guid_string.cc: Convert GUIDs to strings.
31//
32// See guid_string.h for documentation.
33
34#include <wchar.h>
35
36#include "common/windows/string_utils-inl.h"
37
38#include "common/windows/guid_string.h"
39
40namespace google_breakpad {
41
42// static
43wstring GUIDString::GUIDToWString(GUID *guid) {
44  wchar_t guid_string[37];
45  swprintf(
46      guid_string, sizeof(guid_string) / sizeof(guid_string[0]),
47      L"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
48      guid->Data1, guid->Data2, guid->Data3,
49      guid->Data4[0], guid->Data4[1], guid->Data4[2],
50      guid->Data4[3], guid->Data4[4], guid->Data4[5],
51      guid->Data4[6], guid->Data4[7]);
52
53  // remove when VC++7.1 is no longer supported
54  guid_string[sizeof(guid_string) / sizeof(guid_string[0]) - 1] = L'\0';
55
56  return wstring(guid_string);
57}
58
59// static
60wstring GUIDString::GUIDToSymbolServerWString(GUID *guid) {
61  wchar_t guid_string[33];
62  swprintf(
63      guid_string, sizeof(guid_string) / sizeof(guid_string[0]),
64      L"%08X%04X%04X%02X%02X%02X%02X%02X%02X%02X%02X",
65      guid->Data1, guid->Data2, guid->Data3,
66      guid->Data4[0], guid->Data4[1], guid->Data4[2],
67      guid->Data4[3], guid->Data4[4], guid->Data4[5],
68      guid->Data4[6], guid->Data4[7]);
69
70  // remove when VC++7.1 is no longer supported
71  guid_string[sizeof(guid_string) / sizeof(guid_string[0]) - 1] = L'\0';
72
73  return wstring(guid_string);
74}
75
76}  // namespace google_breakpad