utils.h

Go to the documentation of this file.
00001 /*
00002  * File Name: utils.h
00003  */
00004 
00005 /*
00006  * This file is part of uds-plugin-common.
00007  *
00008  * uds-plugin-common is free software: you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation, either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * uds-plugin-common is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00020  */
00021 
00022 /**
00023  * Copyright (C) 2008 iRex Technologies B.V.
00024  * All rights reserved.
00025  */
00026 
00027 #ifndef PLUGIN_UTILS_H
00028 #define PLUGIN_UTILS_H
00029 
00030 #include <glib.h>
00031 
00032 #define MAX_PATH_LEN 1024
00033 
00034 /// @brief Get free memory.
00035 int get_free_memory();
00036 
00037 /// @brief Generate hash code given by a buffe with fixed length.
00038 unsigned int make_hash_code(const char *buffer, unsigned int len);
00039 
00040 /// @brief Finds the leftmost occurrence of the given unicode character in a
00041 ///  UTF-8 encoded string, while limiting the search to len bytes. Ignore case.
00042 const char* utf8_strichr(const char *str, int len, gunichar c);
00043 
00044 /// @brief Finds the rightmost occurrence of the given unicode character in a
00045 ///  UTF-8 encoded string, while limiting the search to len bytes. Ignore case.
00046 const char* utf8_strirchr(const char *str, int len, gunichar c);
00047 
00048 /// @brief Finds the leftmost occurrence of substring in a string.
00049 const char* utf8_strstr(const char *str, const char *sub, bool case_sensitive);
00050 
00051 /// @brief Finds the rightmost occurrence of substring in a string.
00052 const char* utf8_strrstr(const char *str, int len, const char *sub, bool case_sensitive);
00053 
00054 /// @brief Check if the sub string is a whole word.
00055 /// @param str The UTF-8 encoded string.
00056 /// @param sub The sub string to be checked.
00057 /// @param sub_len The length of the sub string.
00058 /// @return true if sub is a whole word.
00059 bool is_whole_word(const char *str, const char *sub, size_t sub_len);
00060 
00061 
00062 /// @brief Get the dir path of 'filename'.
00063 /// @param filename  e.g. /data/wa/sample/rome.jpg 
00064 /// @param dir       dir path e.g. /data/wa/sample
00065 /// @param dir_len   the max len of 'dir' 
00066 /// @return          true has dir, false no dir or error
00067 bool get_dir_path(const char * filename, char * dir, int dir_len);
00068 
00069 /// @brief Get the name of 'filename'.
00070 /// @param filename  e.g. /data/wa/sample/rome.jpg 
00071 /// @param name      name e.g. rome.jpg
00072 /// @param name_len  the max len of 'name' 
00073 /// @return          true has name, false no name or error
00074 bool get_file_name(const char * filename, char *name, int name_len);
00075 
00076 /// @brief Get the extension name from a filename.
00077 /// @param filename  e.g. /data/wa/sample/rome.jpg, or rome.jpg
00078 /// @param ext       extension name e.g. jpg
00079 /// @param ext_len   the max len of 'ext' 
00080 /// @return          true has extension, false no extension or error
00081 bool get_ext_name(const char * filename, char * ext, int ext_len);
00082 
00083 /// @brief Convert the unicode string to utf-8 string.
00084 /// @param ucs_str The input unicode string.
00085 /// @param input_len The length of input buffer.
00086 /// @param utf_str The output utf-8 string buffer.
00087 /// @param output_len The buffer length of output buffer.
00088 /// @return true if conversion succeed, otherwise false is returned.
00089 bool ucs2utf8(char* ucs_str, size_t input_len, char* utf_str, size_t output_len);
00090 
00091 #endif // PLUGIN_UTILS_H
00092 
Generated by  doxygen 1.6.2-20100208