tdf#151548 ContentControls: Add Delete()
[LibreOffice.git] / registry / source / reflwrit.cxx
blob5304d03463c80d928a7b672e70e350559bdeb2d9
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 .
21 #include <sal/types.h>
22 #include <rtl/ustring.h>
24 #include <registry/refltype.hxx>
26 #include "reflcnst.hxx"
29 sal_uInt32 UINT16StringLen(const sal_uInt8* wstring)
31 if (!wstring) return 0;
33 const sal_uInt8* b = wstring;
35 while (b[0] || b[1]) b += sizeof(sal_uInt16);
37 return ((b - wstring) / sizeof(sal_uInt16));
40 sal_uInt32 writeString(sal_uInt8* buffer, const sal_Unicode* v)
42 sal_uInt32 len = rtl_ustr_getLength(v) + 1;
43 sal_uInt32 i;
44 sal_uInt8* buff = buffer;
46 for (i = 0; i < len; i++)
48 buff += writeUINT16(buff, static_cast<sal_uInt16>(v[i]));
51 return (buff - buffer);
54 sal_uInt32 readString(const sal_uInt8* buffer, sal_Unicode* v, sal_uInt32 maxSize)
56 sal_uInt32 len = UINT16StringLen(buffer) + 1;
57 sal_uInt32 i;
58 sal_uInt8* buff = const_cast<sal_uInt8*>(buffer);
60 if(len > maxSize / 2)
62 len = maxSize / 2;
65 for (i = 0; i < (len - 1); i++)
67 sal_uInt16 aChar;
69 buff += readUINT16(buff, aChar);
71 v[i] = static_cast<sal_Unicode>(aChar);
74 v[len - 1] = L'\0';
76 return (buff - buffer);
79 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */