update dev300-m58
[ooovba.git] / cli_ure / source / mono_bridge / rtl_ustring.cs
blob9d3032382891f374a95de72b5afde9c364bf2303
1 /*************************************************************************
3 * $RCSfile: $
5 * $Revision: $
7 * last change: $Author: $ $Date: $
9 * The Contents of this file are made available subject to the terms of
10 * either of the following licenses
12 * - GNU Lesser General Public License Version 2.1
13 * - Sun Industry Standards Source License Version 1.1
15 * Sun Microsystems Inc., October, 2000
17 * GNU Lesser General Public License Version 2.1
18 * =============================================
19 * Copyright 2000 by Sun Microsystems, Inc.
20 * 901 San Antonio Road, Palo Alto, CA 94303, USA
22 * This library is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU Lesser General Public
24 * License version 2.1, as published by the Free Software Foundation.
26 * This library is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 * Lesser General Public License for more details.
31 * You should have received a copy of the GNU Lesser General Public
32 * License along with this library; if not, write to the Free Software
33 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
34 * MA 02111-1307 USA
37 * Sun Industry Standards Source License Version 1.1
38 * =================================================
39 * The contents of this file are subject to the Sun Industry Standards
40 * Source License Version 1.1 (the "License"); You may not use this file
41 * except in compliance with the License. You may obtain a copy of the
42 * License at http://www.openoffice.org/license.html.
44 * Software provided under this License is provided on an "AS IS" basis,
45 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
46 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
47 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
48 * See the License for the specific provisions governing your rights and
49 * obligations concerning the Software.
51 * The Initial Developer of the Original Code is: Sun Microsystems, Inc.
53 * Copyright: 2000 by Sun Microsystems, Inc.
55 * All Rights Reserved.
57 * Contributor(s): _______________________________________
60 ************************************************************************/
62 namespace uno.rtl {
64 using System;
65 using System.Runtime.InteropServices;
66 using System.Text;
68 public unsafe struct UString
70 public int RefCount;
71 public int Length;
72 public char FirstChar;
74 [DllImport("sal")]
75 private static extern void rtl_uString_acquire(void* data);
77 [DllImport("sal")]
78 private static unsafe extern void rtl_uString_release(void* data);
80 [DllImport("sal")]
81 private static unsafe extern void rtl_uString_new(void* data);
83 [DllImport("sal")]
84 private static unsafe extern void rtl_uString_newFromStr_WithLength(
85 void* data,
86 // this should pass a pointer to the original string's char[]
87 [MarshalAs(UnmanagedType.LPWStr)] string value,
88 int len);
90 [DllImport("sal")]
91 private static unsafe extern void rtl_uString_newFromStr_WithLength(
92 void* data,
93 // this should pass a pointer to the stringbuilder's internal char[]
94 [MarshalAs(UnmanagedType.LPWStr)] StringBuilder buffer,
95 int len);
97 public static unsafe void Acquire(UString* us)
99 rtl_uString_acquire(us);
102 public static unsafe void Release(UString* us)
104 rtl_uString_release(us);
107 public static unsafe void New(UString** p)
109 rtl_uString_new(p);
112 public static unsafe void NewFromString(UString **p, string s)
114 rtl_uString_newFromStr_WithLength(p, s, s.Length);
117 public static unsafe void NewFromStringBuilder(UString **p, StringBuilder sb)
119 rtl_uString_newFromStr_WithLength(p, sb, sb.Length);
122 public static unsafe string UStringToString(UString *p)
124 return new String(&(p->FirstChar), 0, p->Length);
128 // FIXME move this to its own file or rename this file to e.g. sal
129 public unsafe struct Mem
131 // FIXME parameter is a sal_Size which is unsigned and has the
132 // size of a native long. Thus this is not 64bit safe. Might have
133 // to write a glue function that always takes 32bit.
134 [DllImport("sal", EntryPoint="rtl_allocateMemory")]
135 public static unsafe extern void *Allocate(int bytes);