4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Haejeong Kim <backto.kim@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
26 #include "mm_file_utils.h"
28 #ifdef __MMFILE_MEM_TRACE__
30 int mmfile_util_wstrlen (unsigned short *wText)
36 debug_error ("wText is NULL\n");
37 return MMFILE_UTIL_FAIL;
42 while ( *(wText+n) != 0 )
50 short __WmLngSwapShort( short aShort )
52 return ( ( aShort << 8 ) + ( aShort >> 8 ) );
56 short* mmfile_swap_2byte_string (short* mszOutput, short* mszInput, int length)
60 for ( i = 0; i < length; i++ )
62 if ( mszInput[i] == 0 )
65 mszOutput[i] = __WmLngSwapShort( mszInput[i] );
75 char *mmfile_string_convert_debug (const char *str, unsigned int len,
76 const char *to_codeset, const char *from_codeset,
82 char *tmp = g_convert (str, len, to_codeset, from_codeset, bytes_read, bytes_written, NULL);
86 fprintf (stderr, "## DEBUG ## %p = g_convert (%p, %u, %p, %p, %p ,%p, %p, %u) by %s() %d\n",
87 tmp, str, len, to_codeset, from_codeset, bytes_read, bytes_written, func, line);
95 char **mmfile_strsplit (const char *string, const char *delimiter)
97 return g_strsplit (string, delimiter, -1);
101 void mmfile_strfreev (char **str_array)
103 g_strfreev(str_array);
107 char *mmfile_strdup_debug (const char *str, const char *func, unsigned int line)
117 fprintf (stderr, "## DEBUG ## %p = strdup (%p) by %s() %d\n", temp, str, func, line);
124 #else /* __MMFILE_MEM_TRACE__ */
127 int mmfile_util_wstrlen (unsigned short *wText)
133 debug_error ("wText is NULL\n");
134 return MMFILE_UTIL_FAIL;
139 while ( *(wText+n) != 0 )
148 char *mmfile_string_convert (const char *str, unsigned int len,
149 const char *to_codeset, const char *from_codeset,
150 unsigned int *bytes_read,
151 unsigned int *bytes_written)
155 result = g_convert (str, len, to_codeset, from_codeset, bytes_read, bytes_written, NULL);
157 /*if converting failed, return duplicated source string.*/
158 if (result == NULL) {
159 #ifdef __MMFILE_TEST_MODE__
160 debug_warning ("text encoding failed.[%s][%d]\n", str, len);
168 char **mmfile_strsplit (const char *string, const char *delimiter)
170 return g_strsplit (string, delimiter, -1);
174 void mmfile_strfreev (char **str_array)
176 g_strfreev(str_array);
180 char *mmfile_strdup (const char *str)
188 #endif /*__MMFILE_MEM_TRACE__*/