1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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;
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;
58 sal_uInt8
* buff
= const_cast<sal_uInt8
*>(buffer
);
65 assert(len
> 0 && "maxSize has to be >= 2");
67 for (i
= 0; i
< len
; i
++)
71 buff
+= readUINT16(buff
, aChar
);
73 v
[i
] = static_cast<sal_Unicode
>(aChar
);
78 return (buff
- buffer
);
81 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */