LibreOffice Module tools (master) 1
globname.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <string.h>
21
23#include <o3tl/sprintf.hxx>
24#include <rtl/character.hxx>
25
26#include <tools/stream.hxx>
27#include <tools/globname.hxx>
28
29// SvGlobalName ----------------------------------------------------------------
31 m_aData( rId )
32{
33}
34
35SvGlobalName::SvGlobalName( sal_uInt32 n1, sal_uInt16 n2, sal_uInt16 n3,
36 sal_uInt8 b8, sal_uInt8 b9, sal_uInt8 b10, sal_uInt8 b11,
37 sal_uInt8 b12, sal_uInt8 b13, sal_uInt8 b14, sal_uInt8 b15 ) :
38 m_aData{ n1, n2, n3, { b8, b9, b10, b11, b12, b13, b14, b15 } }
39{
40}
41
42SvGlobalName::SvGlobalName( const css::uno::Sequence < sal_Int8 >& aSeq )
43{
44 // create SvGlobalName from a platform independent representation
45 if ( aSeq.getLength() == 16 )
46 {
47 m_aData.Data1 = ( ( ( ( ( static_cast<sal_uInt8>(aSeq[0]) << 8 ) + static_cast<sal_uInt8>(aSeq[1]) ) << 8 ) + static_cast<sal_uInt8>(aSeq[2]) ) << 8 ) + static_cast<sal_uInt8>(aSeq[3]);
48 m_aData.Data2 = ( static_cast<sal_uInt8>(aSeq[4]) << 8 ) + static_cast<sal_uInt8>(aSeq[5]);
49 m_aData.Data3 = ( static_cast<sal_uInt8>(aSeq[6]) << 8 ) + static_cast<sal_uInt8>(aSeq[7]);
50 for( int nInd = 0; nInd < 8; nInd++ )
51 m_aData.Data4[nInd] = static_cast<sal_uInt8>(aSeq[nInd+8]);
52 }
53}
54
56{
57 rOStr.WriteUInt32( rObj.m_aData.Data1 );
58 rOStr.WriteUInt16( rObj.m_aData.Data2 );
59 rOStr.WriteUInt16( rObj.m_aData.Data3 );
60 rOStr.WriteBytes( &rObj.m_aData.Data4, 8 );
61 return rOStr;
62}
63
65{
66 rStr.ReadUInt32( rObj.m_aData.Data1 );
67 rStr.ReadUInt16( rObj.m_aData.Data2 );
68 rStr.ReadUInt16( rObj.m_aData.Data3 );
69 rStr.ReadBytes( &rObj.m_aData.Data4, 8 );
70 return rStr;
71}
72
73
74bool SvGlobalName::operator < ( const SvGlobalName & rObj ) const
75{
76 if( m_aData.Data3 < rObj.m_aData.Data3 )
77 return true;
78 else if( m_aData.Data3 > rObj.m_aData.Data3 )
79 return false;
80
81 if( m_aData.Data2 < rObj.m_aData.Data2 )
82 return true;
83 else if( m_aData.Data2 > rObj.m_aData.Data2 )
84 return false;
85
86 return m_aData.Data1 < rObj.m_aData.Data1;
87}
88
89bool SvGlobalName::operator == ( const SvGlobalName & rObj ) const
90{
91 return memcmp(&m_aData, &rObj.m_aData, sizeof(m_aData)) == 0;
92}
93
94void SvGlobalName::MakeFromMemory( void const * pData )
95{
96 memcpy( &m_aData, pData, sizeof( m_aData ) );
97}
98
99bool SvGlobalName::MakeId( std::u16string_view rIdStr )
100{
101 const sal_Unicode *pStr = rIdStr.data();
102 if( rIdStr.size() != 36
103 || '-' != pStr[ 8 ] || '-' != pStr[ 13 ]
104 || '-' != pStr[ 18 ] || '-' != pStr[ 23 ] )
105 return false;
106
107 SvGUID aGuid = {};
108 auto asciiHexDigitToNumber = [](sal_Unicode c) -> sal_uInt8
109 {
110 if (rtl::isAsciiDigit(c))
111 return c - '0';
112 else
113 return rtl::toAsciiUpperCase(c) - 'A' + 10;
114 };
115
116 for( int i = 0; i < 8; i++ )
117 {
118 if( !rtl::isAsciiHexDigit( *pStr ) )
119 return false;
120 aGuid.Data1 = aGuid.Data1 * 16 + asciiHexDigitToNumber( *pStr++ );
121 }
122
123 pStr++;
124 for( int i = 0; i < 4; i++ )
125 {
126 if( !rtl::isAsciiHexDigit( *pStr ) )
127 return false;
128 aGuid.Data2 = aGuid.Data2 * 16 + asciiHexDigitToNumber( *pStr++ );
129 }
130
131 pStr++;
132 for( int i = 0; i < 4; i++ )
133 {
134 if( !rtl::isAsciiHexDigit( *pStr ) )
135 return false;
136 aGuid.Data3 = aGuid.Data3 * 16 + asciiHexDigitToNumber( *pStr++ );
137 }
138
139 pStr++;
140 for( int i = 0; i < 16; i++ )
141 {
142 if( !rtl::isAsciiHexDigit( *pStr ) )
143 return false;
144 aGuid.Data4[i/2] = aGuid.Data4[i/2] * 16 + asciiHexDigitToNumber( *pStr++ );
145 if( i == 3 )
146 pStr++;
147 }
148
149 m_aData = aGuid;
150 return true;
151}
152
154{
155 char buf[ 37 ];
156 int n = o3tl::sprintf(buf,
157 "%8.8" SAL_PRIXUINT32 "-%4.4X-%4.4X-%2.2x%2.2x-%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x",
161 assert(n == 36);
162 return OUString::createFromAscii(std::string_view(buf, n));
163}
164
165css::uno::Sequence < sal_Int8 > SvGlobalName::GetByteSequence() const
166{
167 // platform independent representation of a "GlobalName"
168 // maybe transported remotely
173}
174
175/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvGUID m_aData
Definition: globname.hxx:72
OUString GetHexName() const
Definition: globname.cxx:153
void MakeFromMemory(void const *pData)
Definition: globname.cxx:94
SvGlobalName()=default
bool MakeId(std::u16string_view rId)
Definition: globname.cxx:99
css::uno::Sequence< sal_Int8 > GetByteSequence() const
Definition: globname.cxx:165
bool operator==(const SvGlobalName &rObj) const
Definition: globname.cxx:89
bool operator<(const SvGlobalName &rObj) const
Definition: globname.cxx:74
std::size_t WriteBytes(const void *pData, std::size_t nSize)
Definition: stream.cxx:1192
SvStream & WriteUInt16(sal_uInt16 nUInt16)
Definition: stream.cxx:949
SvStream & WriteUInt32(sal_uInt32 nUInt32)
Definition: stream.cxx:950
SvStream & ReadUInt32(sal_uInt32 &rUInt32)
Definition: stream.cxx:822
std::size_t ReadBytes(void *pData, std::size_t nSize)
Definition: stream.cxx:1114
SvStream & ReadUInt16(sal_uInt16 &rUInt16)
Definition: stream.cxx:821
static css::uno::Sequence< sal_Int8 > GetSequenceClassID(sal_uInt32 n1, sal_uInt16 n2, sal_uInt16 n3, sal_uInt8 b8, sal_uInt8 b9, sal_uInt8 b10, sal_uInt8 b11, sal_uInt8 b12, sal_uInt8 b13, sal_uInt8 b14, sal_uInt8 b15)
MapData m_aData
SvStream & operator>>(SvStream &rStr, SvGlobalName &rObj)
Definition: globname.cxx:64
SvStream & WriteSvGlobalName(SvStream &rOStr, const SvGlobalName &rObj)
Definition: globname.cxx:55
sal_Int64 n
Sequence< sal_Int8 > aSeq
std::unique_ptr< sal_Int32[]> pData
int n2
int n1
sal_uInt32 n3
int i
int sprintf(char(&s)[N], char const *format, T &&... arguments)
sal_uInt8 Data4[8]
Definition: globname.hxx:30
sal_uInt16 Data3
Definition: globname.hxx:29
sal_uInt16 Data2
Definition: globname.hxx:28
sal_uInt32 Data1
Definition: globname.hxx:27
unsigned char sal_uInt8
sal_uInt16 sal_Unicode