LibreOffice Module registry (master) 1
reflwrit.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
21#include <sal/types.h>
22#include <rtl/ustring.h>
23
24#include <registry/refltype.hxx>
25
26#include "reflcnst.hxx"
27
28
29sal_uInt32 UINT16StringLen(const sal_uInt8* wstring)
30{
31 if (!wstring) return 0;
32
33 const sal_uInt8* b = wstring;
34
35 while (b[0] || b[1]) b += sizeof(sal_uInt16);
36
37 return ((b - wstring) / sizeof(sal_uInt16));
38}
39
40sal_uInt32 writeString(sal_uInt8* buffer, const sal_Unicode* v)
41{
42 sal_uInt32 len = rtl_ustr_getLength(v) + 1;
43 sal_uInt32 i;
44 sal_uInt8* buff = buffer;
45
46 for (i = 0; i < len; i++)
47 {
48 buff += writeUINT16(buff, static_cast<sal_uInt16>(v[i]));
49 }
50
51 return (buff - buffer);
52}
53
54sal_uInt32 readString(const sal_uInt8* buffer, sal_Unicode* v, sal_uInt32 maxSize)
55{
56 sal_uInt32 len = UINT16StringLen(buffer) + 1;
57 sal_uInt32 i;
58 sal_uInt8* buff = const_cast<sal_uInt8*>(buffer);
59
60 if(len > maxSize / 2)
61 {
62 len = maxSize / 2;
63 }
64
65 for (i = 0; i < (len - 1); i++)
66 {
67 sal_uInt16 aChar;
68
69 buff += readUINT16(buff, aChar);
70
71 v[i] = static_cast<sal_Unicode>(aChar);
72 }
73
74 v[len - 1] = L'\0';
75
76 return (buff - buffer);
77}
78
79/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
float v
int i
sal_uInt32 readUINT16(const sal_uInt8 *buffer, sal_uInt16 &v)
Definition: reflcnst.hxx:102
sal_uInt32 writeUINT16(sal_uInt8 *buffer, sal_uInt16 v)
Definition: reflcnst.hxx:94
sal_uInt32 writeString(sal_uInt8 *buffer, const sal_Unicode *v)
Definition: reflwrit.cxx:40
sal_uInt32 readString(const sal_uInt8 *buffer, sal_Unicode *v, sal_uInt32 maxSize)
Definition: reflwrit.cxx:54
sal_uInt32 UINT16StringLen(const sal_uInt8 *wstring)
Definition: reflwrit.cxx:29
unsigned char sal_uInt8
sal_uInt16 sal_Unicode