1 |
/******************************************************************************* |
= |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2005 IBM Corporation and others. |
|
2 |
* Copyright (c) 2000, 2005 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
|
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
|
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
|
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
|
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
|
7 |
* |
8 |
* Contributors: |
|
8 |
* Contributors: |
9 |
* IBM Corporation - initial API and implementation |
|
9 |
* IBM Corporation - initial API and implementation |
10 |
*******************************************************************************/ |
|
10 |
*******************************************************************************/ |
11 |
|
|
11 |
|
|
|
<> |
12 |
/******************************************************************************* |
|
|
|
13 |
* Additions/modifications to this source file by Oracle America, Inc. 2011 |
|
|
|
14 |
*******************************************************************************/ |
|
|
|
15 |
|
12 |
#include "TypeConverter.h" |
= |
16 |
#include "TypeConverter.h" |
13 |
|
|
17 |
|
14 |
const UGL_Char* getNativeStringData(UGL_String string, UGL_Boolean* shouldFree) { |
|
18 |
const UGL_Char* getNativeStringData(UGL_String string, UGL_Boolean* shouldFree) { |
15 |
*shouldFree = FALSE; |
|
19 |
*shouldFree = FALSE; |
16 |
return string; |
|
20 |
return string; |
17 |
} |
|
21 |
} |
18 |
|
|
22 |
|
19 |
UGL_Int getNativeStringLength(UGL_String string) { |
|
23 |
UGL_Int getNativeStringLength(UGL_String string) { |
20 |
// make sure null-terminated! |
|
24 |
// make sure null-terminated! |
21 |
return lstrlen(string); |
|
25 |
return lstrlen(string); |
22 |
} |
|
26 |
} |
23 |
|
|
27 |
|
24 |
UGL_String convertToNativeString(const UGL_Char* data, UGL_Int length, UGL_Boolean* shouldFree) { |
|
28 |
UGL_String convertToNativeString(const UGL_Char* data, UGL_Int length, UGL_Boolean* shouldFree) { |
|
|
<> |
29 |
if (length >= 0) { |
|
|
|
30 |
UGL_String string = (UGL_String)malloc((length + 1) * sizeof(UGL_Char)); |
|
|
|
31 |
if (string) { |
|
|
|
32 |
wcsncpy(string, data, length); |
|
|
|
33 |
string[length] = 0; |
|
|
|
34 |
*shouldFree = UGL_TRUE; |
|
|
|
35 |
return string; |
|
|
|
36 |
} |
|
|
|
37 |
} |
|
|
|
38 |
|
25 |
*shouldFree = FALSE; |
|
39 |
*shouldFree = UGL_FALSE; |
26 |
return (UGL_String)data; |
|
40 |
return (UGL_String)NULL; |
27 |
} |
= |
41 |
} |
28 |
|
|
42 |
|
29 |
void freeNativeStringData(const UGL_Char* data) { |
|
43 |
void freeNativeStringData(const UGL_Char* data) { |
30 |
// Do nothing since we never return TRUE for freeing string data |
|
44 |
// Do nothing since we never return TRUE for freeing string data |
31 |
} |
|
45 |
} |
32 |
|
|
46 |
|
33 |
void freeNativeString(UGL_String string) { |
|
47 |
void freeNativeString(UGL_String string) { |
34 |
free((void *)string); |
|
48 |
free((void *)string); |
35 |
} |
|
49 |
} |
36 |
|
|
50 |
|
37 |
void freeNativeStringArray(UGL_StringArray stringArray) { |
|
51 |
void freeNativeStringArray(UGL_StringArray stringArray) { |
38 |
// Each of the string elements needs to be free'd as well |
|
52 |
// Each of the string elements needs to be free'd as well |
39 |
int index=0; |
|
53 |
int index=0; |
40 |
while (stringArray[index] != NULL) { |
|
54 |
while (stringArray[index] != NULL) { |
41 |
free(stringArray[index]); |
|
55 |
free(stringArray[index]); |
42 |
index++; |
|
56 |
index++; |
43 |
} |
|
57 |
} |
44 |
|
|
58 |
|
45 |
free((void *)stringArray); |
|
59 |
free((void *)stringArray); |
46 |
} |
|
60 |
} |
47 |
|
|
61 |
|
48 |
void freeNativeIntArray(UGL_IntArray intArray) { |
|
62 |
void freeNativeIntArray(UGL_IntArray intArray) { |
49 |
free((void *)intArray); |
|
63 |
free((void *)intArray); |
50 |
} |
|
64 |
} |
51 |
|
|
65 |
|
52 |
void freeNativeByteArray(UGL_ByteArray array) { |
|
66 |
void freeNativeByteArray(UGL_ByteArray array) { |
53 |
free((void *)array); |
|
67 |
free((void *)array); |
54 |
} |
|
68 |
} |
55 |
|
|
69 |
|
56 |
UGL_Int getNativeStringArrayLength(UGL_StringArray nativeArray) { |
|
70 |
UGL_Int getNativeStringArrayLength(UGL_StringArray nativeArray) { |
57 |
UGL_Int length = 0; |
|
71 |
UGL_Int length = 0; |
58 |
if (nativeArray == NULL) return 0; |
|
72 |
if (nativeArray == NULL) return 0; |
59 |
while (nativeArray[length] != NULL) {length++;} |
|
73 |
while (nativeArray[length] != NULL) {length++;} |
60 |
return length; |
|
74 |
return length; |
61 |
} |
|
75 |
} |
62 |
|
|
76 |
|
63 |
UGL_String getNativeStringArrayElement(UGL_StringArray nativeArray, UGL_Int index, UGL_Boolean* shouldFreeResult) { |
|
77 |
UGL_String getNativeStringArrayElement(UGL_StringArray nativeArray, UGL_Int index, UGL_Boolean* shouldFreeResult) { |
64 |
*shouldFreeResult = FALSE; |
|
78 |
*shouldFreeResult = FALSE; |
65 |
if (nativeArray == NULL) return NULL; |
|
79 |
if (nativeArray == NULL) return NULL; |
66 |
return nativeArray[index]; |
|
80 |
return nativeArray[index]; |
67 |
} |
|
81 |
} |