From 400086a5c852cc8c75975aa0490bf802744471b8 Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 23 Aug 2012 13:38:16 -0500 Subject: [PATCH] Add more C samples Closes #237 --- lib/linguist/samples.json | 1203 ++++++++++++++++--- samples/C/rf_io.c | 1267 ++++++++++++++++++++ samples/C/rf_io.h | 682 +++++++++++ samples/C/rfc_string.c | 2348 +++++++++++++++++++++++++++++++++++++ samples/C/rfc_string.h | 1459 +++++++++++++++++++++++ 5 files changed, 6807 insertions(+), 152 deletions(-) create mode 100644 samples/C/rf_io.c create mode 100644 samples/C/rf_io.h create mode 100644 samples/C/rfc_string.c create mode 100644 samples/C/rfc_string.h diff --git a/lib/linguist/samples.json b/lib/linguist/samples.json index 88867a77..e6225630 100644 --- a/lib/linguist/samples.json +++ b/lib/linguist/samples.json @@ -257,8 +257,8 @@ ".gemrc" ] }, - "tokens_total": 300219, - "languages_total": 268, + "tokens_total": 316785, + "languages_total": 272, "tokens": { "Apex": { "global": 70, @@ -947,103 +947,103 @@ "World": 1 }, "C": { - "#include": 112, - "const": 204, - "char": 192, + "#include": 137, + "const": 302, + "char": 394, "*blob_type": 2, - ";": 2809, - "struct": 217, + ";": 4024, + "struct": 221, "blob": 6, "*lookup_blob": 2, - "(": 2899, - "unsigned": 116, + "(": 4679, + "unsigned": 130, "*sha1": 16, - ")": 2913, - "{": 1023, + ")": 4679, + "{": 1369, "object": 10, "*obj": 5, "lookup_object": 2, "sha1": 20, - "if": 638, + "if": 938, "obj": 18, - "return": 304, + "return": 501, "create_object": 2, "OBJ_BLOB": 3, "alloc_blob_node": 1, - "-": 1279, + "-": 1723, "type": 27, - "error": 71, + "error": 96, "sha1_to_hex": 8, "typename": 2, "NULL": 281, - "}": 1025, - "*": 63, - "int": 305, + "}": 1382, + "*": 71, + "int": 308, "parse_blob_buffer": 2, "*item": 10, - "void": 210, + "void": 241, "*buffer": 6, - "long": 97, - "size": 59, + "long": 98, + "size": 108, "item": 24, "object.parsed": 4, - "#ifndef": 9, + "#ifndef": 22, "BLOB_H": 2, - "#define": 53, - "extern": 32, - "#endif": 43, + "#define": 207, + "extern": 34, + "#endif": 107, "git_cache_init": 1, "git_cache": 4, "*cache": 4, "size_t": 40, "git_cached_obj_freeptr": 1, "free_ptr": 2, - "<": 140, + "<": 185, "git__size_t_powerof2": 1, "cache": 26, "size_mask": 6, "lru_count": 1, "free_obj": 4, "git_mutex_init": 1, - "&": 285, + "&": 423, "lock": 6, "nodes": 10, "git__malloc": 3, - "sizeof": 52, + "sizeof": 67, "git_cached_obj": 5, "GITERR_CHECK_ALLOC": 3, "memset": 4, "git_cache_free": 1, - "i": 162, - "for": 37, - "+": 284, - "[": 244, - "]": 244, + "i": 363, + "for": 88, + "+": 543, + "[": 420, + "]": 420, "git_cached_obj_decref": 3, "git__free": 15, "*git_cache_get": 1, "git_oid": 7, "*oid": 2, - "uint32_t": 6, + "uint32_t": 144, "hash": 12, "*node": 2, "*result": 1, - "memcpy": 6, + "memcpy": 34, "oid": 17, "id": 7, "git_mutex_lock": 2, "node": 9, - "&&": 189, + "&&": 224, "git_oid_cmp": 6, "git_cached_obj_incref": 3, - "result": 12, + "result": 48, "git_mutex_unlock": 2, "*git_cache_try_store": 1, "*_entry": 1, "*entry": 2, "_entry": 1, "entry": 17, - "else": 120, + "else": 170, "save_commit_buffer": 3, "*commit_type": 2, "static": 80, @@ -1059,9 +1059,9 @@ "lookup_commit_reference_gently": 1, "*lookup_commit_or_die": 2, "*ref_name": 2, - "*c": 15, + "*c": 69, "lookup_commit_reference": 2, - "c": 192, + "c": 247, "die": 5, "_": 3, "ref_name": 2, @@ -1075,7 +1075,7 @@ "*commit": 10, "get_sha1": 1, "name": 12, - "||": 112, + "||": 133, "parse_commit": 3, "parse_commit_date": 2, "*buf": 9, @@ -1084,7 +1084,7 @@ "buf": 56, "tail": 12, "memcmp": 6, - "while": 41, + "while": 64, "dateptr": 2, "strtoul": 2, "commit_graft": 13, @@ -1095,31 +1095,31 @@ "lo": 6, "hi": 5, "mi": 5, - "/": 5, + "/": 7, "*graft": 3, "cmp": 9, "graft": 10, "register_commit_graft": 2, "ignore_dups": 2, "pos": 7, - "free": 8, + "free": 62, "alloc_nr": 1, "xrealloc": 2, "parse_commit_buffer": 3, - "buffer": 9, + "buffer": 10, "*bufptr": 1, "parent": 7, "commit_list": 35, "**pptr": 1, - "<=>": 7, + "<=>": 15, "bufptr": 12, "46": 1, "tree": 3, "5": 1, "45": 1, - "n": 20, + "n": 37, "bogus": 1, - "s": 22, + "s": 139, "get_sha1_hex": 2, "lookup_tree": 1, "pptr": 5, @@ -1130,18 +1130,18 @@ "7": 1, "47": 1, "bad": 1, - "in": 1, + "in": 11, "nr_parent": 3, "grafts_replace_parents": 1, - "continue": 19, + "continue": 20, "new_parent": 6, "lookup_commit": 2, "commit_list_insert": 2, "next": 8, - "date": 4, + "date": 5, "enum": 29, "object_type": 1, - "ret": 24, + "ret": 142, "read_sha1_file": 1, "find_commit_subject": 2, "*commit_buffer": 2, @@ -1149,7 +1149,7 @@ "*eol": 1, "*p": 9, "commit_buffer": 1, - "a": 13, + "a": 28, "b_date": 3, "b": 23, "a_date": 2, @@ -1248,18 +1248,18 @@ "clear_commit_marks_for_object_array": 1, "object_array": 2, "sort_in_topological_order": 1, - "**": 4, + "**": 6, "list": 1, "lifo": 1, "FLEX_ARRAY": 1, - "typedef": 15, + "typedef": 18, "*read_graft_line": 1, - "len": 23, + "len": 29, "*lookup_commit_graft": 1, "*get_merge_bases": 1, "*rev1": 1, "*rev2": 1, - "cleanup": 2, + "cleanup": 12, "*get_merge_bases_many": 1, "*one": 1, "**twos": 1, @@ -1295,7 +1295,7 @@ "append_merge_tag_headers": 1, "***tail": 1, "commit_tree": 1, - "*ret": 2, + "*ret": 20, "*author": 2, "*sign_commit": 2, "commit_tree_extended": 1, @@ -1324,7 +1324,7 @@ "": 1, "": 1, "": 1, - "#ifdef": 17, + "#ifdef": 44, "CONFIG_SMP": 1, "DEFINE_MUTEX": 1, "cpu_add_remove_lock": 3, @@ -1349,7 +1349,7 @@ "get_online_cpus": 2, "might_sleep": 1, "cpu_hotplug.active_writer": 6, - "current": 3, + "current": 5, "cpu_hotplug.refcount": 3, "EXPORT_SYMBOL_GPL": 4, "put_online_cpus": 2, @@ -1357,12 +1357,12 @@ "wake_up_process": 1, "cpu_hotplug_begin": 4, "likely": 1, - "break": 182, + "break": 241, "__set_current_state": 1, "TASK_UNINTERRUPTIBLE": 1, "schedule": 1, "cpu_hotplug_done": 4, - "#else": 11, + "#else": 56, "__ref": 6, "register_cpu_notifier": 2, "notifier_block": 3, @@ -1375,7 +1375,7 @@ "nr_to_call": 2, "*nr_calls": 1, "__raw_notifier_call_chain": 1, - "v": 6, + "v": 7, "nr_calls": 9, "notifier_to_errno": 1, "cpu_notify": 5, @@ -1390,7 +1390,7 @@ "cpu_online": 5, "rcu_read_lock": 1, "for_each_process": 2, - "p": 51, + "p": 60, "*t": 1, "t": 27, "find_lock_task_mm": 1, @@ -1423,7 +1423,7 @@ "err": 38, "__cpu_disable": 1, "CPU_DYING": 1, - "|": 82, + "|": 123, "param": 2, "hcpu": 10, "_cpu_down": 3, @@ -1438,7 +1438,7 @@ "CPU_DOWN_PREPARE": 1, "CPU_DOWN_FAILED": 2, "__func__": 2, - "goto": 85, + "goto": 93, "out_release": 3, "__stop_machine": 1, "cpumask_of": 1, @@ -1448,7 +1448,7 @@ "CPU_DEAD": 1, "CPU_POST_DEAD": 1, "cpu_down": 2, - "out": 11, + "out": 18, "__cpuinit": 3, "_cpu_up": 3, "*idle": 1, @@ -1469,8 +1469,8 @@ "*pgdat": 1, "cpu_possible": 1, "KERN_ERR": 5, - "#if": 17, - "defined": 7, + "#if": 45, + "defined": 24, "CONFIG_IA64": 1, "cpu_to_node": 1, "node_online": 1, @@ -1513,13 +1513,13 @@ "cpu_hotplug_pm_callback": 2, "action": 2, "*ptr": 1, - "switch": 31, - "case": 217, + "switch": 40, + "case": 258, "PM_SUSPEND_PREPARE": 1, "PM_HIBERNATION_PREPARE": 1, "PM_POST_SUSPEND": 1, "PM_POST_HIBERNATION": 1, - "default": 22, + "default": 30, "NOTIFY_DONE": 1, "NOTIFY_OK": 1, "cpu_hotplug_pm_sync_init": 2, @@ -1531,7 +1531,7 @@ "MASK_DECLARE_1": 3, "x": 12, "UL": 1, - "<<": 15, + "<<": 55, "MASK_DECLARE_2": 3, "MASK_DECLARE_4": 3, "MASK_DECLARE_8": 9, @@ -1567,7 +1567,7 @@ "init_cpu_present": 1, "*src": 3, "cpumask_copy": 3, - "src": 3, + "src": 16, "init_cpu_possible": 1, "init_cpu_online": 1, "*diff_prefix_from_pathspec": 1, @@ -1588,28 +1588,28 @@ "git_buf_free": 4, "diff_pathspec_is_interesting": 2, "*str": 1, - "count": 6, - "false": 4, - "true": 4, - "str": 8, - "strings": 1, + "count": 10, + "false": 77, + "true": 73, + "str": 162, + "strings": 5, "diff_path_matches_pathspec": 3, "git_diff_list": 17, "*diff": 8, "*path": 2, "git_attr_fnmatch": 4, "*match": 3, - "diff": 84, + "diff": 93, "pathspec.length": 1, "git_vector_foreach": 4, - "match": 14, + "match": 16, "p_fnmatch": 1, "pattern": 3, "path": 20, "FNM_NOMATCH": 1, "GIT_ATTR_FNMATCH_HASWILD": 1, "strncmp": 1, - "length": 2, + "length": 57, "GIT_ATTR_FNMATCH_NEGATIVE": 1, "git_diff_delta": 19, "*diff_delta__alloc": 1, @@ -1654,7 +1654,7 @@ "assert": 41, "GIT_DELTA_MODIFIED": 3, "old_file.mode": 2, - "mode": 9, + "mode": 11, "old_file.size": 1, "file_size": 6, "old_file.flags": 2, @@ -1669,17 +1669,17 @@ "*temp": 1, "old_entry": 5, "new_entry": 5, - "temp": 1, + "temp": 11, "new_oid": 3, "git_oid_iszero": 2, "*diff_strdup_prefix": 1, - "strlen": 8, + "strlen": 16, "git_pool_strcat": 1, "git_pool_strndup": 1, "diff_delta__cmp": 3, "*da": 1, "*db": 3, - "strcmp": 19, + "strcmp": 20, "da": 2, "db": 10, "config_bool": 5, @@ -1713,7 +1713,7 @@ "new_prefix": 2, "DIFF_NEW_PREFIX_DEFAULT": 1, "*swap": 1, - "swap": 1, + "swap": 9, "pathspec.count": 2, "*pattern": 1, "pathspec.strings": 1, @@ -1775,7 +1775,7 @@ "*sub": 1, "GIT_DIFF_IGNORE_SUBMODULES": 1, "git_submodule_lookup": 1, - "sub": 2, + "sub": 12, "ignore": 1, "GIT_SUBMODULE_IGNORE_ALL": 1, "use_noid": 2, @@ -1818,14 +1818,14 @@ "onto_pool": 7, "git_vector": 1, "onto_new": 6, - "j": 119, + "j": 202, "onto": 7, - "from": 5, + "from": 16, "deltas.length": 4, "*o": 4, "GIT_VECTOR_GET": 2, "*f": 2, - "f": 15, + "f": 180, "o": 18, "diff_delta__merge_like_cgit": 1, "git_vector_swap": 1, @@ -1842,12 +1842,12 @@ "pager_command_config": 2, "*var": 1, "*data": 11, - "data": 67, + "data": 68, "prefixcmp": 3, - "var": 3, + "var": 7, "cmd": 46, "git_config_maybe_bool": 1, - "value": 4, + "value": 5, "xstrdup": 2, "check_pager_config": 3, "c.cmd": 1, @@ -1871,7 +1871,7 @@ "subdir": 3, "chdir": 2, "die_errno": 3, - "errno": 19, + "errno": 20, "saved_errno": 1, "git_version_string": 1, "GIT_VERSION": 1, @@ -1880,7 +1880,7 @@ "USE_PAGER": 3, "NEED_WORK_TREE": 18, "cmd_struct": 4, - "option": 7, + "option": 9, "run_builtin": 2, "help": 4, "stat": 3, @@ -1900,7 +1900,7 @@ "st.st_mode": 2, "S_ISSOCK": 1, "fflush": 2, - "ferror": 1, + "ferror": 2, "fclose": 5, "handle_internal_command": 3, "commands": 3, @@ -2012,7 +2012,7 @@ "*argv0": 1, "argv0": 2, "ARRAY_SIZE": 1, - "exit": 16, + "exit": 20, "execv_dashed_external": 2, "STRBUF_INIT": 1, "*tmp": 1, @@ -2061,21 +2061,21 @@ "vec": 2, ".data": 1, ".len": 3, - "": 4, + "": 7, "HELLO_H": 2, "hello": 1, "": 5, "": 1, "": 3, - "": 2, - "": 3, + "": 3, + "": 4, "": 2, "ULLONG_MAX": 10, "MIN": 3, "HTTP_PARSER_DEBUG": 4, "SET_ERRNO": 47, "e": 4, - "do": 8, + "do": 15, "parser": 334, "http_errno": 11, "error_lineno": 3, @@ -2106,12 +2106,12 @@ "CLOSE": 4, "*method_strings": 1, "XX": 63, - "num": 8, - "string": 2, + "num": 24, + "string": 18, "#string": 1, "HTTP_METHOD_MAP": 3, "#undef": 5, - "tokens": 3, + "tokens": 5, "int8_t": 3, "unhex": 3, "HTTP_PARSER_STRICT": 5, @@ -2183,7 +2183,7 @@ "PARSING_HEADER": 2, "header_states": 1, "h_general": 23, - "0": 1, + "0": 11, "h_C": 3, "h_CO": 3, "h_CON": 3, @@ -2203,10 +2203,10 @@ "h_connection_keep_alive": 4, "h_connection_close": 4, "Macros": 1, - "character": 1, + "character": 11, "classes": 1, "depends": 1, - "on": 1, + "on": 4, "strict": 1, "define": 14, "CR": 18, @@ -2224,7 +2224,7 @@ "IS_URL_CHAR": 6, "IS_HOST_CHAR": 4, "0x80": 1, - "endif": 1, + "endif": 6, "start_state": 1, "HTTP_REQUEST": 7, "cond": 1, @@ -2263,7 +2263,7 @@ "HPE_INVALID_CONSTANT": 3, "method": 39, "HTTP_HEAD": 2, - "index": 53, + "index": 57, "STRICT_CHECK": 15, "HPE_INVALID_VERSION": 12, "http_major": 11, @@ -2324,18 +2324,18 @@ "body_mark": 2, "HPE_INVALID_CHUNK_SIZE": 2, "HPE_INVALID_INTERNAL_STATE": 1, - "1": 1, + "1": 2, "HPE_UNKNOWN": 1, "Does": 1, - "the": 3, - "need": 1, - "to": 2, - "see": 1, - "an": 1, - "EOF": 3, + "the": 91, + "need": 5, + "to": 36, + "see": 2, + "an": 2, + "EOF": 26, "find": 1, - "end": 18, - "of": 1, + "end": 48, + "of": 43, "message": 1, "http_should_keep_alive": 2, "http_method_str": 1, @@ -2368,25 +2368,25 @@ "field_data": 5, ".off": 2, "xffff": 1, - "uint16_t": 6, + "uint16_t": 12, "http_parser_pause": 2, "paused": 3, "HPE_PAUSED": 2, "http_parser_h": 2, - "__cplusplus": 2, + "__cplusplus": 6, "HTTP_PARSER_VERSION_MAJOR": 1, "HTTP_PARSER_VERSION_MINOR": 1, - "": 1, + "": 2, "_WIN32": 2, "__MINGW32__": 1, - "_MSC_VER": 2, + "_MSC_VER": 4, "__int8": 2, "__int16": 2, "int16_t": 1, "__int32": 2, - "int32_t": 1, - "__int64": 2, - "int64_t": 1, + "int32_t": 112, + "__int64": 3, + "int64_t": 2, "ssize_t": 1, "": 1, "*1024": 4, @@ -2460,7 +2460,7 @@ "on_header_value": 1, "on_body": 1, "on_message_complete": 1, - "off": 5, + "off": 8, "*http_method_str": 1, "*http_errno_name": 1, "*http_errno_description": 1, @@ -2471,8 +2471,8 @@ "BUFFER_SPAN": 9, "MKD_LI_END": 1, "gperf_case_strncmp": 1, - "s1": 2, - "s2": 2, + "s1": 6, + "s2": 6, "GPERF_DOWNCASE": 1, "GPERF_CASE_STRNCMP": 1, "link_ref": 2, @@ -2561,7 +2561,7 @@ "SUNDOWN_VER_MAJOR": 1, "SUNDOWN_VER_MINOR": 1, "SUNDOWN_VER_REVISION": 1, - "": 2, + "": 4, "": 2, "": 1, "": 1, @@ -2632,7 +2632,7 @@ "uv__stream_close": 1, "uv__process_child_init": 2, "uv_process_options_t": 2, - "options": 17, + "options": 62, "stdio_count": 7, "int*": 2, "options.flags": 4, @@ -2661,12 +2661,12 @@ "SPAWN_WAIT_EXEC": 5, "uv_spawn": 1, "uv_loop_t*": 1, - "loop": 7, + "loop": 9, "uv_process_t*": 3, - "char**": 1, + "char**": 7, "save_our_env": 3, "options.stdio_count": 4, - "malloc": 2, + "malloc": 3, "signal_pipe": 7, "pollfd": 1, "pfd": 2, @@ -2709,7 +2709,7 @@ "self": 6, "*res": 2, "szres": 8, - "encoding": 8, + "encoding": 13, "rb_funcall": 14, "rb_intern": 15, "rb_str_buf_new": 2, @@ -2757,7 +2757,7 @@ "": 2, "": 1, "": 1, - "": 1, + "": 2, "": 1, "sharedObjectsStruct": 1, "shared": 1, @@ -2940,13 +2940,13 @@ "server.syslog_enabled": 3, "syslog": 1, "redisLog": 33, - "...": 1, - "va_list": 1, + "...": 127, + "va_list": 3, "ap": 4, "REDIS_MAX_LOGMSG_LEN": 1, - "va_start": 1, + "va_start": 3, "vsnprintf": 1, - "va_end": 1, + "va_end": 3, "redisLogFromHandler": 2, "server.daemonize": 5, "O_APPEND": 2, @@ -3004,7 +3004,7 @@ "key": 9, "dictGenHashFunction": 5, "dictSdsHash": 4, - "char*": 7, + "char*": 153, "dictSdsCaseHash": 2, "dictGenCaseHashFunction": 1, "dictEncObjKeyCompare": 4, @@ -3025,7 +3025,7 @@ "htNeedsResize": 3, "dict": 11, "*dict": 2, - "used": 7, + "used": 10, "dictSlots": 3, "dictSize": 10, "DICT_HT_INITIAL_SIZE": 2, @@ -3046,8 +3046,8 @@ "dictEnableResize": 1, "dictDisableResize": 1, "activeExpireCycle": 2, - "iteration": 3, - "start": 6, + "iteration": 6, + "start": 10, "timelimit": 5, "*REDIS_EXPIRELOOKUPS_TIME_PERC/REDIS_HZ/100": 1, "expired": 4, @@ -3239,7 +3239,7 @@ "shared.lpop": 1, "REDIS_SHARED_INTEGERS": 1, "shared.integers": 2, - "void*": 1, + "void*": 130, "REDIS_SHARED_BULKHDR_LEN": 1, "shared.mbulkhdr": 1, "shared.bulkhdr": 1, @@ -3464,8 +3464,8 @@ "addReplyMultiBulkLen": 1, "addReplyBulkLongLong": 2, "bytesToHuman": 3, - "*s": 1, - "sprintf": 4, + "*s": 2, + "sprintf": 10, "n/": 3, "LL*1024*1024": 2, "LL*1024*1024*1024": 1, @@ -3541,7 +3541,7 @@ "REDIS_REPL_WAIT_BGSAVE_END": 1, "REDIS_REPL_SEND_BULK": 1, "REDIS_REPL_ONLINE": 1, - "float": 11, + "float": 17, "self_ru.ru_stime.tv_sec": 1, "self_ru.ru_stime.tv_usec/1000000": 1, "self_ru.ru_utime.tv_sec": 1, @@ -3585,7 +3585,7 @@ "daemonize": 2, "STDIN_FILENO": 1, "STDERR_FILENO": 2, - "version": 2, + "version": 3, "usage": 2, "redisAsciiArt": 2, "*16": 2, @@ -3625,6 +3625,905 @@ "aeSetBeforeSleepProc": 1, "aeMain": 1, "aeDeleteEventLoop": 1, + "": 1, + "": 2, + "": 2, + "//": 257, + "rfUTF8_IsContinuationbyte": 1, + "e.t.c.": 1, + "rfFReadLine_UTF8": 5, + "FILE*": 64, + "utf8": 36, + "uint32_t*": 34, + "byteLength": 197, + "bufferSize": 6, + "eof": 53, + "bytesN": 98, + "bIndex": 5, + "RF_NEWLINE_CRLF": 1, + "newLineFound": 1, + "*bufferSize": 1, + "RF_OPTION_FGETS_READBYTESN": 5, + "RF_MALLOC": 47, + "tempBuff": 6, + "RF_LF": 10, + "buff": 95, + "RF_SUCCESS": 14, + "RE_FILE_EOF": 22, + "found": 20, + "*eofReached": 14, + "LOG_ERROR": 64, + "RF_HEXEQ_UI": 7, + "rfFgetc_UTF32BE": 3, + "else//": 14, + "undo": 5, + "peek": 5, + "ahead": 5, + "file": 6, + "pointer": 5, + "fseek": 19, + "SEEK_CUR": 19, + "rfFgets_UTF32LE": 2, + "eofReached": 4, + "rfFgetc_UTF32LE": 4, + "rfFgets_UTF16BE": 2, + "rfFgetc_UTF16BE": 4, + "rfFgets_UTF16LE": 2, + "rfFgetc_UTF16LE": 4, + "rfFgets_UTF8": 2, + "rfFgetc_UTF8": 3, + "RF_HEXEQ_C": 9, + "fgetc": 9, + "check": 8, + "RE_FILE_READ": 2, + "cp": 12, + "c2": 13, + "c3": 9, + "c4": 5, + "i_READ_CHECK": 20, + "///": 4, + "success": 4, + "cc": 24, + "we": 10, + "more": 2, + "bytes": 225, + "xC0": 3, + "xC1": 1, + "RE_UTF8_INVALID_SEQUENCE_INVALID_BYTE": 6, + "RE_UTF8_INVALID_SEQUENCE_END": 6, + "rfUTF8_IsContinuationByte": 12, + "RE_UTF8_INVALID_SEQUENCE_CONBYTE": 6, + "decoded": 3, + "codepoint": 47, + "F": 29, + "xE0": 2, + "xF": 5, + "decode": 6, + "xF0": 2, + "RF_HEXGE_C": 1, + "xBF": 2, + "//invalid": 1, + "byte": 6, + "are": 6, + "xFF": 1, + "//if": 1, + "needing": 1, + "than": 5, + "swapE": 21, + "v1": 38, + "v2": 26, + "rfUTILS_Endianess": 24, + "RF_LITTLE_ENDIAN": 23, + "fread": 12, + "endianess": 40, + "needed": 9, + "rfUTILS_SwapEndianUS": 10, + "RF_HEXGE_US": 4, + "xD800": 8, + "RF_HEXLE_US": 4, + "xDFFF": 8, + "RF_HEXL_US": 8, + "RF_HEXG_US": 8, + "xDBFF": 4, + "RE_UTF16_INVALID_SEQUENCE": 20, + "RE_UTF16_NO_SURRPAIR": 2, + "xDC00": 4, + "user": 2, + "wants": 2, + "ff": 10, + "uint16_t*": 11, + "surrogate": 4, + "pair": 4, + "existence": 2, + "RF_BIG_ENDIAN": 10, + "rfUTILS_SwapEndianUI": 11, + "rfFback_UTF32BE": 2, + "i_FSEEK_CHECK": 14, + "rfFback_UTF32LE": 2, + "rfFback_UTF16BE": 2, + "rfFback_UTF16LE": 2, + "rfFback_UTF8": 2, + "depending": 1, + "number": 19, + "read": 1, + "backwards": 1, + "RE_UTF8_INVALID_SEQUENCE": 2, + "REFU_IO_H": 2, + "": 2, + "opening": 2, + "bracket": 4, + "calling": 4, + "C": 4, + "xA": 1, + "RF_CR": 1, + "xD": 1, + "REFU_WIN32_VERSION": 1, + "i_PLUSB_WIN32": 2, + "foff_rft": 2, + "off64_t": 1, + "///Fseek": 1, + "and": 15, + "Ftelll": 1, + "definitions": 1, + "rfFseek": 2, + "i_FILE_": 16, + "i_OFFSET_": 4, + "i_WHENCE_": 4, + "_fseeki64": 1, + "rfFtell": 2, + "_ftelli64": 1, + "fseeko64": 1, + "ftello64": 1, + "i_DECLIMEX_": 121, + "rfFReadLine_UTF16BE": 6, + "rfFReadLine_UTF16LE": 4, + "rfFReadLine_UTF32BE": 1, + "rfFReadLine_UTF32LE": 4, + "rfFgets_UTF32BE": 1, + "RF_IAMHERE_FOR_DOXYGEN": 22, + "rfPopen": 2, + "command": 2, + "i_rfPopen": 2, + "i_CMD_": 2, + "i_MODE_": 2, + "i_rfLMS_WRAP2": 5, + "rfPclose": 1, + "stream": 2, + "///closing": 1, + "#endif//include": 1, + "guards": 2, + "": 1, + "": 2, + "local": 5, + "stack": 5, + "memory": 4, + "RF_OPTION_DEFAULT_ARGUMENTS": 24, + "RF_String*": 222, + "rfString_Create": 4, + "i_rfString_Create": 3, + "READ_VSNPRINTF_ARGS": 5, + "rfUTF8_VerifySequence": 7, + "RF_FAILURE": 24, + "RE_STRING_INIT_FAILURE": 8, + "buffAllocated": 11, + "RF_String": 27, + "i_NVrfString_Create": 3, + "i_rfString_CreateLocal1": 3, + "RF_OPTION_SOURCE_ENCODING": 30, + "RF_UTF8": 8, + "characterLength": 16, + "*codepoints": 2, + "rfLMS_MacroEvalPtr": 2, + "RF_LMS": 6, + "RF_UTF16_LE": 9, + "RF_UTF16_BE": 7, + "codepoints": 44, + "i/2": 2, + "#elif": 10, + "RF_UTF32_LE": 3, + "RF_UTF32_BE": 3, + "UTF16": 4, + "rfUTF16_Decode": 5, + "rfUTF16_Decode_swap": 5, + "RF_UTF16_BE//": 2, + "RF_UTF32_LE//": 2, + "copy": 4, + "UTF32": 4, + "into": 8, + "RF_UTF32_BE//": 2, + "": 2, + "any": 3, + "other": 16, + "UTF": 17, + "8": 15, + "encode": 2, + "them": 3, + "rfUTF8_Encode": 4, + "While": 2, + "attempting": 2, + "create": 2, + "temporary": 4, + "given": 5, + "sequence": 6, + "could": 2, + "not": 6, + "be": 6, + "properly": 2, + "encoded": 2, + "RE_UTF8_ENCODING": 2, + "End": 2, + "Non": 2, + "code=": 2, + "normally": 1, + "since": 5, + "here": 5, + "have": 2, + "validity": 2, + "get": 4, + "Error": 2, + "at": 3, + "String": 11, + "Allocation": 2, + "due": 2, + "invalid": 2, + "rfLMS_Push": 4, + "Memory": 4, + "allocation": 3, + "Local": 2, + "Stack": 2, + "failed": 2, + "Insufficient": 2, + "space": 4, + "Consider": 2, + "compiling": 2, + "library": 3, + "with": 9, + "bigger": 3, + "Quitting": 2, + "proccess": 2, + "RE_LOCALMEMSTACK_INSUFFICIENT": 8, + "i_NVrfString_CreateLocal": 3, + "during": 1, + "rfString_Init": 3, + "i_rfString_Init": 3, + "i_NVrfString_Init": 3, + "rfString_Create_cp": 2, + "rfString_Init_cp": 3, + "RF_HEXLE_UI": 8, + "RF_HEXGE_UI": 6, + "C0": 2, + "ffff": 4, + "xFC0": 4, + "xF000": 2, + "xE": 2, + "F000": 2, + "C0000": 2, + "E": 2, + "RE_UTF8_INVALID_CODE_POINT": 2, + "rfString_Create_i": 2, + "numLen": 8, + "max": 4, + "is": 17, + "most": 3, + "environment": 3, + "so": 4, + "chars": 3, + "will": 3, + "certainly": 3, + "fit": 3, + "it": 12, + "strcpy": 4, + "rfString_Init_i": 2, + "rfString_Create_f": 2, + "rfString_Init_f": 2, + "rfString_Create_UTF16": 2, + "rfString_Init_UTF16": 3, + "utf8ByteLength": 34, + "last": 1, + "utf": 1, + "null": 4, + "termination": 3, + "byteLength*2": 1, + "allocate": 1, + "same": 1, + "as": 4, + "different": 1, + "RE_INPUT": 1, + "ends": 3, + "rfString_Create_UTF32": 2, + "rfString_Init_UTF32": 3, + "codeBuffer": 9, + "xFEFF": 1, + "big": 14, + "endian": 20, + "xFFFE0000": 1, + "little": 7, + "according": 1, + "standard": 1, + "no": 4, + "BOM": 1, + "means": 1, + "rfUTF32_Length": 1, + "i_rfString_Assign": 3, + "dest": 7, + "sourceP": 2, + "source": 8, + "RF_REALLOC": 9, + "rfString_Assign_char": 2, + "<5)>": 1, + "rfString_Create_nc": 3, + "i_rfString_Create_nc": 3, + "bytesWritten": 2, + "i_NVrfString_Create_nc": 3, + "rfString_Init_nc": 4, + "i_rfString_Init_nc": 3, + "i_NVrfString_Init_nc": 3, + "rfString_Destroy": 2, + "rfString_Deinit": 3, + "rfString_ToUTF16": 4, + "charsN": 5, + "rfUTF8_Decode": 2, + "rfUTF16_Encode": 1, + "rfString_ToUTF32": 4, + "rfString_Length": 5, + "RF_STRING_ITERATE_START": 9, + "RF_STRING_ITERATE_END": 9, + "rfString_GetChar": 2, + "thisstr": 210, + "codePoint": 18, + "RF_STRING_INDEX_OUT_OF_BOUNDS": 2, + "rfString_BytePosToCodePoint": 7, + "rfString_BytePosToCharPos": 4, + "thisstrP": 32, + "bytepos": 12, + "before": 3, + "charPos": 8, + "byteI": 7, + "i_rfString_Equal": 3, + "s1P": 2, + "s2P": 2, + "i_rfString_Find": 5, + "sstrP": 6, + "optionsP": 11, + "sstr": 39, + "*optionsP": 8, + "RF_BITFLAG_ON": 5, + "RF_CASE_IGNORE": 2, + "strstr": 2, + "RF_MATCH_WORD": 5, + "exact": 4, + "": 1, + "0x5a": 1, + "0x7a": 1, + "substring": 5, + "search": 1, + "zero": 2, + "equals": 1, + "then": 1, + "okay": 1, + "rfString_Equal": 4, + "RFS_": 8, + "ERANGE": 1, + "RE_STRING_TOFLOAT_UNDERFLOW": 1, + "RE_STRING_TOFLOAT": 1, + "rfString_Copy_OUT": 2, + "srcP": 6, + "rfString_Copy_IN": 2, + "dst": 15, + "rfString_Copy_chars": 2, + "bytePos": 23, + "terminate": 1, + "i_rfString_ScanfAfter": 3, + "afterstrP": 2, + "format": 4, + "afterstr": 5, + "sscanf": 1, + "<=0)>": 1, + "Counts": 1, + "how": 1, + "many": 1, + "times": 1, + "occurs": 1, + "inside": 2, + "i_rfString_Count": 5, + "sstr2": 2, + "move": 12, + "rfString_FindBytePos": 10, + "rfString_Tokenize": 2, + "sep": 3, + "tokensN": 2, + "RF_String**": 2, + "*tokensN": 1, + "rfString_Count": 4, + "lstr": 6, + "lstrP": 1, + "rstr": 24, + "rstrP": 5, + "rfString_After": 4, + "rfString_Beforev": 4, + "parNP": 6, + "i_rfString_Beforev": 16, + "parN": 10, + "*parNP": 2, + "minPos": 17, + "thisPos": 8, + "argList": 8, + "va_arg": 2, + "i_rfString_Before": 5, + "i_rfString_After": 5, + "afterP": 2, + "after": 6, + "rfString_Afterv": 4, + "i_rfString_Afterv": 16, + "minPosLength": 3, + "go": 8, + "i_rfString_Append": 3, + "otherP": 4, + "strncat": 1, + "rfString_Append_i": 2, + "rfString_Append_f": 2, + "i_rfString_Prepend": 3, + "goes": 1, + "i_rfString_Remove": 6, + "numberP": 1, + "*numberP": 1, + "occurences": 5, + "done": 1, + "<=thisstr->": 1, + "i_rfString_KeepOnly": 3, + "keepstrP": 2, + "keepLength": 2, + "charValue": 12, + "*keepChars": 1, + "keepstr": 5, + "exists": 6, + "charBLength": 5, + "keepChars": 4, + "*keepLength": 1, + "rfString_Iterate_Start": 6, + "rfString_Iterate_End": 4, + "": 1, + "does": 1, + "exist": 2, + "back": 1, + "cover": 1, + "that": 9, + "effectively": 1, + "gets": 1, + "deleted": 1, + "rfUTF8_FromCodepoint": 1, + "this": 5, + "kind": 1, + "non": 1, + "clean": 1, + "way": 1, + "macro": 2, + "internally": 1, + "uses": 1, + "byteIndex_": 12, + "variable": 1, + "use": 1, + "determine": 1, + "backs": 1, + "memmove": 1, + "by": 1, + "contiuing": 1, + "make": 3, + "sure": 2, + "position": 1, + "won": 1, + "array": 1, + "rfString_PruneStart": 2, + "nBytePos": 23, + "rfString_PruneEnd": 2, + "RF_STRING_ITERATEB_START": 2, + "RF_STRING_ITERATEB_END": 2, + "rfString_PruneMiddleB": 2, + "pBytePos": 15, + "indexing": 1, + "works": 1, + "pbytePos": 2, + "pth": 2, + "include": 6, + "rfString_PruneMiddleF": 2, + "got": 1, + "all": 2, + "i_rfString_Replace": 6, + "numP": 1, + "*numP": 1, + "RF_StringX": 2, + "just": 1, + "finding": 1, + "foundN": 10, + "bSize": 4, + "bytePositions": 17, + "bSize*sizeof": 1, + "rfStringX_FromString_IN": 1, + "temp.bIndex": 2, + "temp.bytes": 1, + "temp.byteLength": 1, + "rfStringX_Deinit": 1, + "replace": 3, + "removed": 2, + "one": 2, + "orSize": 5, + "nSize": 4, + "number*diff": 1, + "strncpy": 3, + "smaller": 1, + "diff*number": 1, + "remove": 1, + "equal": 1, + "i_rfString_StripStart": 3, + "subP": 7, + "RF_String*sub": 2, + "noMatch": 8, + "*subValues": 2, + "subLength": 6, + "subValues": 8, + "*subLength": 2, + "i_rfString_StripEnd": 3, + "lastBytePos": 4, + "testity": 2, + "i_rfString_Strip": 3, + "res1": 2, + "rfString_StripStart": 3, + "res2": 2, + "rfString_StripEnd": 3, + "rfString_Create_fUTF8": 2, + "rfString_Init_fUTF8": 3, + "unused": 3, + "rfString_Assign_fUTF8": 2, + "FILE*f": 2, + "utf8BufferSize": 4, + "function": 6, + "rfString_Append_fUTF8": 2, + "rfString_Append": 5, + "rfString_Create_fUTF16": 2, + "rfString_Init_fUTF16": 3, + "rfString_Assign_fUTF16": 2, + "rfString_Append_fUTF16": 2, + "char*utf8": 3, + "rfString_Create_fUTF32": 2, + "rfString_Init_fUTF32": 3, + "<0)>": 1, + "Failure": 1, + "initialize": 1, + "reading": 1, + "Little": 1, + "Endian": 1, + "32": 1, + "bytesN=": 1, + "rfString_Assign_fUTF32": 2, + "rfString_Append_fUTF32": 2, + "i_rfString_Fwrite": 5, + "sP": 2, + "encodingP": 1, + "*utf32": 1, + "utf16": 11, + "*encodingP": 1, + "fwrite": 5, + "logging": 5, + "utf32": 10, + "i_WRITE_CHECK": 1, + "RE_FILE_WRITE": 1, + "REFU_USTRING_H": 2, + "": 1, + "RF_MODULE_STRINGS//": 1, + "included": 1, + "module": 3, + "": 1, + "argument": 1, + "wrapping": 1, + "functionality": 1, + "": 1, + "unicode": 2, + "xFF0FFFF": 1, + "rfUTF8_IsContinuationByte2": 1, + "b__": 3, + "0xBF": 1, + "pragma": 1, + "pack": 2, + "push": 1, + "internal": 4, + "author": 1, + "Lefteris": 1, + "09": 1, + "12": 1, + "2010": 1, + "endinternal": 1, + "brief": 1, + "A": 1, + "representation": 2, + "The": 1, + "Refu": 2, + "Unicode": 1, + "has": 2, + "two": 1, + "versions": 1, + "One": 1, + "ref": 1, + "what": 1, + "operations": 1, + "can": 2, + "performed": 1, + "extended": 3, + "Strings": 2, + "Functions": 1, + "convert": 1, + "but": 1, + "always": 2, + "Once": 1, + "been": 1, + "created": 1, + "assumed": 1, + "valid": 1, + "every": 1, + "performs": 1, + "unless": 1, + "otherwise": 1, + "specified": 1, + "All": 1, + "functions": 2, + "which": 1, + "isinherited": 1, + "StringX": 2, + "their": 1, + "description": 1, + "safely": 1, + "specific": 1, + "or": 1, + "needs": 1, + "manipulate": 1, + "Extended": 1, + "To": 1, + "documentation": 1, + "even": 1, + "clearer": 1, + "should": 2, + "marked": 1, + "notinherited": 1, + "cppcode": 1, + "constructor": 1, + "i_StringCHandle": 1, + "@endcpp": 1, + "@endinternal": 1, + "*/": 1, + "#pragma": 1, + "pop": 1, + "i_rfString_CreateLocal": 2, + "__VA_ARGS__": 66, + "RP_SELECT_FUNC_IF_NARGIS": 5, + "i_SELECT_RF_STRING_CREATE": 1, + "i_SELECT_RF_STRING_CREATE1": 1, + "i_SELECT_RF_STRING_CREATE0": 1, + "///Internal": 1, + "creates": 1, + "i_SELECT_RF_STRING_CREATELOCAL": 1, + "i_SELECT_RF_STRING_CREATELOCAL1": 1, + "i_SELECT_RF_STRING_CREATELOCAL0": 1, + "i_SELECT_RF_STRING_INIT": 1, + "i_SELECT_RF_STRING_INIT1": 1, + "i_SELECT_RF_STRING_INIT0": 1, + "code": 2, + "i_SELECT_RF_STRING_CREATE_NC": 1, + "i_SELECT_RF_STRING_CREATE_NC1": 1, + "i_SELECT_RF_STRING_CREATE_NC0": 1, + "i_SELECT_RF_STRING_INIT_NC": 1, + "i_SELECT_RF_STRING_INIT_NC1": 1, + "i_SELECT_RF_STRING_INIT_NC0": 1, + "//@": 1, + "rfString_Assign": 2, + "i_DESTINATION_": 2, + "i_SOURCE_": 2, + "rfString_ToUTF8": 2, + "i_STRING_": 2, + "rfString_ToCstr": 2, + "uint32_t*length": 1, + "string_": 9, + "startCharacterPos_": 4, + "characterUnicodeValue_": 4, + "j_": 6, + "//Two": 1, + "macros": 1, + "accomplish": 1, + "going": 1, + "backwards.": 1, + "This": 1, + "its": 1, + "pair.": 1, + "rfString_IterateB_Start": 1, + "characterPos_": 5, + "b_index_": 6, + "c_index_": 3, + "rfString_IterateB_End": 1, + "i_STRING1_": 2, + "i_STRING2_": 2, + "i_rfLMSX_WRAP2": 4, + "rfString_Find": 3, + "i_THISSTR_": 60, + "i_SEARCHSTR_": 26, + "i_OPTIONS_": 28, + "i_rfLMS_WRAP3": 4, + "i_RFI8_": 54, + "RF_SELECT_FUNC_IF_NARGGT": 10, + "i_NPSELECT_RF_STRING_FIND": 1, + "i_NPSELECT_RF_STRING_FIND1": 1, + "RF_COMPILE_ERROR": 33, + "i_NPSELECT_RF_STRING_FIND0": 1, + "RF_SELECT_FUNC": 10, + "i_SELECT_RF_STRING_FIND": 1, + "i_SELECT_RF_STRING_FIND2": 1, + "i_SELECT_RF_STRING_FIND3": 1, + "i_SELECT_RF_STRING_FIND1": 1, + "i_SELECT_RF_STRING_FIND0": 1, + "rfString_ToInt": 1, + "int32_t*": 1, + "rfString_ToDouble": 1, + "double*": 1, + "rfString_ScanfAfter": 2, + "i_AFTERSTR_": 8, + "i_FORMAT_": 2, + "i_VAR_": 2, + "i_rfLMSX_WRAP4": 11, + "i_NPSELECT_RF_STRING_COUNT": 1, + "i_NPSELECT_RF_STRING_COUNT1": 1, + "i_NPSELECT_RF_STRING_COUNT0": 1, + "i_SELECT_RF_STRING_COUNT": 1, + "i_SELECT_RF_STRING_COUNT2": 1, + "i_rfLMSX_WRAP3": 5, + "i_SELECT_RF_STRING_COUNT3": 1, + "i_SELECT_RF_STRING_COUNT1": 1, + "i_SELECT_RF_STRING_COUNT0": 1, + "rfString_Between": 3, + "i_rfString_Between": 4, + "i_NPSELECT_RF_STRING_BETWEEN": 1, + "i_NPSELECT_RF_STRING_BETWEEN1": 1, + "i_NPSELECT_RF_STRING_BETWEEN0": 1, + "i_SELECT_RF_STRING_BETWEEN": 1, + "i_SELECT_RF_STRING_BETWEEN4": 1, + "i_LEFTSTR_": 6, + "i_RIGHTSTR_": 6, + "i_RESULT_": 12, + "i_rfLMSX_WRAP5": 9, + "i_SELECT_RF_STRING_BETWEEN5": 1, + "i_SELECT_RF_STRING_BETWEEN3": 1, + "i_SELECT_RF_STRING_BETWEEN2": 1, + "i_SELECT_RF_STRING_BETWEEN1": 1, + "i_SELECT_RF_STRING_BETWEEN0": 1, + "i_NPSELECT_RF_STRING_BEFOREV": 1, + "i_NPSELECT_RF_STRING_BEFOREV1": 1, + "RF_SELECT_FUNC_IF_NARGGT2": 2, + "i_LIMSELECT_RF_STRING_BEFOREV": 1, + "i_NPSELECT_RF_STRING_BEFOREV0": 1, + "i_LIMSELECT_RF_STRING_BEFOREV1": 1, + "i_LIMSELECT_RF_STRING_BEFOREV0": 1, + "i_SELECT_RF_STRING_BEFOREV": 1, + "i_SELECT_RF_STRING_BEFOREV5": 1, + "i_ARG1_": 56, + "i_ARG2_": 56, + "i_ARG3_": 56, + "i_ARG4_": 56, + "i_RFUI8_": 28, + "i_SELECT_RF_STRING_BEFOREV6": 1, + "i_rfLMSX_WRAP6": 2, + "i_SELECT_RF_STRING_BEFOREV7": 1, + "i_rfLMSX_WRAP7": 2, + "i_SELECT_RF_STRING_BEFOREV8": 1, + "i_rfLMSX_WRAP8": 2, + "i_SELECT_RF_STRING_BEFOREV9": 1, + "i_rfLMSX_WRAP9": 2, + "i_SELECT_RF_STRING_BEFOREV10": 1, + "i_rfLMSX_WRAP10": 2, + "i_SELECT_RF_STRING_BEFOREV11": 1, + "i_rfLMSX_WRAP11": 2, + "i_SELECT_RF_STRING_BEFOREV12": 1, + "i_rfLMSX_WRAP12": 2, + "i_SELECT_RF_STRING_BEFOREV13": 1, + "i_rfLMSX_WRAP13": 2, + "i_SELECT_RF_STRING_BEFOREV14": 1, + "i_rfLMSX_WRAP14": 2, + "i_SELECT_RF_STRING_BEFOREV15": 1, + "i_rfLMSX_WRAP15": 2, + "i_SELECT_RF_STRING_BEFOREV16": 1, + "i_rfLMSX_WRAP16": 2, + "i_SELECT_RF_STRING_BEFOREV17": 1, + "i_rfLMSX_WRAP17": 2, + "i_SELECT_RF_STRING_BEFOREV18": 1, + "i_rfLMSX_WRAP18": 2, + "rfString_Before": 3, + "i_NPSELECT_RF_STRING_BEFORE": 1, + "i_NPSELECT_RF_STRING_BEFORE1": 1, + "i_NPSELECT_RF_STRING_BEFORE0": 1, + "i_SELECT_RF_STRING_BEFORE": 1, + "i_SELECT_RF_STRING_BEFORE3": 1, + "i_SELECT_RF_STRING_BEFORE4": 1, + "i_SELECT_RF_STRING_BEFORE2": 1, + "i_SELECT_RF_STRING_BEFORE1": 1, + "i_SELECT_RF_STRING_BEFORE0": 1, + "i_NPSELECT_RF_STRING_AFTER": 1, + "i_NPSELECT_RF_STRING_AFTER1": 1, + "i_NPSELECT_RF_STRING_AFTER0": 1, + "i_SELECT_RF_STRING_AFTER": 1, + "i_SELECT_RF_STRING_AFTER3": 1, + "i_OUTSTR_": 6, + "i_SELECT_RF_STRING_AFTER4": 1, + "i_SELECT_RF_STRING_AFTER2": 1, + "i_SELECT_RF_STRING_AFTER1": 1, + "i_SELECT_RF_STRING_AFTER0": 1, + "i_NPSELECT_RF_STRING_AFTERV": 1, + "i_NPSELECT_RF_STRING_AFTERV1": 1, + "i_LIMSELECT_RF_STRING_AFTERV": 1, + "i_NPSELECT_RF_STRING_AFTERV0": 1, + "i_LIMSELECT_RF_STRING_AFTERV1": 1, + "i_LIMSELECT_RF_STRING_AFTERV0": 1, + "i_SELECT_RF_STRING_AFTERV": 1, + "i_SELECT_RF_STRING_AFTERV5": 1, + "i_SELECT_RF_STRING_AFTERV6": 1, + "i_SELECT_RF_STRING_AFTERV7": 1, + "i_SELECT_RF_STRING_AFTERV8": 1, + "i_SELECT_RF_STRING_AFTERV9": 1, + "i_SELECT_RF_STRING_AFTERV10": 1, + "i_SELECT_RF_STRING_AFTERV11": 1, + "i_SELECT_RF_STRING_AFTERV12": 1, + "i_SELECT_RF_STRING_AFTERV13": 1, + "i_SELECT_RF_STRING_AFTERV14": 1, + "i_SELECT_RF_STRING_AFTERV15": 1, + "i_SELECT_RF_STRING_AFTERV16": 1, + "i_SELECT_RF_STRING_AFTERV17": 1, + "i_SELECT_RF_STRING_AFTERV18": 1, + "i_OTHERSTR_": 4, + "rfString_Prepend": 2, + "rfString_Remove": 3, + "i_NPSELECT_RF_STRING_REMOVE": 1, + "i_NPSELECT_RF_STRING_REMOVE1": 1, + "i_NPSELECT_RF_STRING_REMOVE0": 1, + "i_SELECT_RF_STRING_REMOVE": 1, + "i_SELECT_RF_STRING_REMOVE2": 1, + "i_REPSTR_": 16, + "i_RFUI32_": 8, + "i_SELECT_RF_STRING_REMOVE3": 1, + "i_NUMBER_": 12, + "i_SELECT_RF_STRING_REMOVE4": 1, + "i_SELECT_RF_STRING_REMOVE1": 1, + "i_SELECT_RF_STRING_REMOVE0": 1, + "rfString_KeepOnly": 2, + "I_KEEPSTR_": 2, + "rfString_Replace": 3, + "i_NPSELECT_RF_STRING_REPLACE": 1, + "i_NPSELECT_RF_STRING_REPLACE1": 1, + "i_NPSELECT_RF_STRING_REPLACE0": 1, + "i_SELECT_RF_STRING_REPLACE": 1, + "i_SELECT_RF_STRING_REPLACE3": 1, + "i_SELECT_RF_STRING_REPLACE4": 1, + "i_SELECT_RF_STRING_REPLACE5": 1, + "i_SELECT_RF_STRING_REPLACE2": 1, + "i_SELECT_RF_STRING_REPLACE1": 1, + "i_SELECT_RF_STRING_REPLACE0": 1, + "i_SUBSTR_": 6, + "rfString_Strip": 2, + "rfString_Fwrite": 2, + "i_NPSELECT_RF_STRING_FWRITE": 1, + "i_NPSELECT_RF_STRING_FWRITE1": 1, + "i_NPSELECT_RF_STRING_FWRITE0": 1, + "i_SELECT_RF_STRING_FWRITE": 1, + "i_SELECT_RF_STRING_FWRITE3": 1, + "i_STR_": 8, + "i_ENCODING_": 4, + "i_SELECT_RF_STRING_FWRITE2": 1, + "i_SELECT_RF_STRING_FWRITE1": 1, + "i_SELECT_RF_STRING_FWRITE0": 1, + "rfString_Fwrite_fUTF8": 1, + "closing": 1, + "#error": 1, + "Attempted": 1, + "manipulation": 1, + "flag": 1, + "off.": 1, + "Rebuild": 1, + "added": 1, + "you": 1, + "#endif//": 1, "yajl_status_to_string": 1, "yajl_status": 4, "statStr": 6, @@ -28252,7 +29151,7 @@ "AppleScript": 1862, "Arduino": 20, "AutoHotkey": 3, - "C": 27901, + "C": 44467, "C++": 9539, "Ceylon": 50, "CoffeeScript": 2955, @@ -28322,7 +29221,7 @@ "AppleScript": 7, "Arduino": 1, "AutoHotkey": 1, - "C": 18, + "C": 22, "C++": 16, "Ceylon": 1, "CoffeeScript": 9, @@ -28387,5 +29286,5 @@ "XSLT": 1, "YAML": 1 }, - "md5": "62da0e867a535d88012d4bde71ece816" + "md5": "08cfeb3d8d3d58fadb8afc1affc43cc5" } \ No newline at end of file diff --git a/samples/C/rf_io.c b/samples/C/rf_io.c new file mode 100644 index 00000000..b7991a26 --- /dev/null +++ b/samples/C/rf_io.c @@ -0,0 +1,1267 @@ +/** +** Copyright (c) 2011-2012, Karapetsas Eleftherios +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: +** 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the distribution. +** 3. Neither the name of the Original Author of Refu nor the names of its contributors may be used to endorse or promote products derived from +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +** INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +** SERVICES;LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**/ + +#include + +#include +#include +#include "io_private.h" +#include +#include // for rfUTF8_IsContinuationbyte +#include // for malloc +#include // for memcpy e.t.c. + + +// Reads a UTF-8 file descriptor until end of line or EOF is found and returns a UTF-8 byte buffer +int32_t rfFReadLine_UTF8(FILE* f,char** utf8,uint32_t* byteLength,uint32_t* bufferSize,char* eof) +{ + int32_t bytesN; + uint32_t bIndex=0; +#ifdef RF_NEWLINE_CRLF + char newLineFound = false; +#endif + // allocate the utf8 buffer + *bufferSize = RF_OPTION_FGETS_READBYTESN+4; + RF_MALLOC(*utf8,*bufferSize) + *byteLength = 0; + // read the start + bytesN = rfFgets_UTF8(*utf8,RF_OPTION_FGETS_READBYTESN,f,eof); + (*byteLength)+=bytesN; + + if(bytesN < 0)//error check + { + LOG_ERROR("Failed to read a UTF-8 file",bytesN); + free(*utf8); + return bytesN; + } + // if the last character was a newline we are done + if(*((*utf8)+bytesN-1) == (char)RF_LF) + { +#ifdef RF_NEWLINE_CRLF + if(*((*utf8)+bytesN-2) == (char)RF_CR) + { + *((*utf8)+bytesN-2) = RF_LF; + *((*utf8)+bytesN-1) = '\0'; + (*byteLength)-=1; + } +#endif + return bytesN; + } + + if(bytesN >= RF_OPTION_FGETS_READBYTESN && (*eof)==false)// if the size does not fit in the buffer and if we did not reach the end of file + { + // keep reading until we have read all until newline or EOF + while(bytesN >= RF_OPTION_FGETS_READBYTESN && (*eof)==false) + { + if(*byteLength+RF_OPTION_FGETS_READBYTESN+4 >= *bufferSize) + { + *bufferSize=(*byteLength+RF_OPTION_FGETS_READBYTESN+4)*2; + RF_REALLOC(*utf8,char,*bufferSize); + } + bIndex += bytesN; + bytesN = rfFgets_UTF8((*utf8)+bIndex,RF_OPTION_FGETS_READBYTESN,f,eof); + (*byteLength)+=bytesN; + if(bytesN < 0)// error check + { + LOG_ERROR("StringX Initialization from file failed in file reading",bytesN); + free(*utf8); + return bytesN; + } + // if the last character was a newline break + if(*((*utf8)+bIndex+bytesN-1) == (char)RF_LF) + { +#ifdef RF_NEWLINE_CRLF + newLineFound = true; +#endif + break; + } + }// end of reading loop +#ifdef RF_NEWLINE_CRLF + if(newLineFound==true) + if(*((*utf8)+bIndex+bytesN-2) == (char)RF_CR) + { + *((*utf8)+bIndex+bytesN-2) = RF_LF; + *((*utf8)+bIndex+bytesN-1) = '\0'; + (*byteLength)-=1; + } + +#endif + return bIndex; + }// end of size not fitting the initial buffer case + else + { +#ifdef RF_NEWLINE_CRLF + // if the last character was a newline + if(*((*utf8)+bytesN-1) == (char)RF_LF) + { + if(*((*utf8)+bytesN-2) == (char)RF_CR) + { + *((*utf8)+bytesN-2) = RF_LF; + *((*utf8)+bytesN-1) = '\0'; + (*byteLength)-=1; + } + } +#endif + // case of size fully fitting the buffer + return bytesN; + } +} +// Reads a Little Endian UTF-16 file descriptor until end of line or EOF is found and returns a UTF-8 byte buffer +int32_t rfFReadLine_UTF16LE(FILE* f,char** utf8,uint32_t* byteLength,char* eof) +{ + char buff[RF_OPTION_FGETS_READBYTESN+5]; + int32_t bytesN; + uint32_t *codepoints,charsN,bIndex=0,buffSize=RF_OPTION_FGETS_READBYTESN+5,accum; + char* tempBuff = 0,buffAllocated=false; + + bytesN = rfFgets_UTF16LE(buff,RF_OPTION_FGETS_READBYTESN,f,eof); + accum = (uint32_t)bytesN; + tempBuff = &buff[0];// point the tempBuff to the initial buffer for now + if(bytesN < 0)// error check + { + LOG_ERROR("Failed to read from a Little Endian UTF-16 file",bytesN); + return bytesN; + } + else if(bytesN >= RF_OPTION_FGETS_READBYTESN && (*eof)==false)// if the size does not fit in the buffer and if we did not reach the EOF + { + // allocate the temporary buffer and move the previous buffer's content inside it + buffSize=buffSize*2+5; + RF_MALLOC(tempBuff,buffSize); + memcpy(tempBuff,buff,bytesN); + bIndex=bytesN; + buffAllocated = true; + // keep reading until we have read all until newline or EOF + do + { + bytesN = rfFgets_UTF16LE(tempBuff+bIndex,RF_OPTION_FGETS_READBYTESN,f,eof); + accum += bytesN; + if(bytesN < 0)// error check + { + LOG_ERROR("Failed to read from a Little Endian UTF-16 file",bytesN); + free(tempBuff); + return bytesN; + } + // realloc to have more space in the buffer for reading if needed + if(accum+RF_OPTION_FGETS_READBYTESN+5 >= buffSize) + { + buffSize=(accum+RF_OPTION_FGETS_READBYTESN+5)*2; + RF_REALLOC(tempBuff,char,buffSize); + } + bIndex += bytesN; + // if the last character was newline break off the loop + if( *(uint16_t*)(tempBuff+bIndex-2)== (uint16_t)RF_LF) + break; + }while(bytesN >= RF_OPTION_FGETS_READBYTESN && (*eof)==false);//end of reading loop + }// end of size not fitting the initial buffer case + if(bytesN >0)//determine the amount of bytes read + bIndex+=bytesN; + // allocate the codepoints + RF_MALLOC(codepoints,(bIndex+5)*2) + // decode it into codepoints + if(rfUTF16_Decode(tempBuff,&charsN,codepoints)==false) + { + free(codepoints); + if(buffAllocated==true) + free(tempBuff); + LOG_ERROR("Failed to Decode UTF-16 from a File Descriptor",RE_UTF16_INVALID_SEQUENCE); + return RE_UTF16_INVALID_SEQUENCE; + } + // now encode these codepoints into UTF8 + if(((*utf8)=rfUTF8_Encode(codepoints,charsN,byteLength)) == 0) + { + free(codepoints); + if(buffAllocated==true) + free(tempBuff); + LOG_ERROR("Failed to encode the File Descriptor's UTF-16 bytestream to UTF-8",RE_UTF8_ENCODING); + return RE_UTF8_ENCODING;// error + } + // success + free(codepoints); + if(buffAllocated==true) + free(tempBuff); +#ifdef RF_NEWLINE_CRLF + // if the last character was a newline + if(*((*utf8)+(*byteLength)-1) == (char)RF_LF) + { + if(*((*utf8)+(*byteLength)-2) == (char)RF_CR) + { + *((*utf8)+(*byteLength)-2) = RF_LF; + *((*utf8)+(*byteLength)-1) = '\0'; + (*byteLength)-=1; + } + } +#endif + + + return bIndex; +} +// Reads a Big Endian UTF-16 file descriptor until end of line or EOF is found and returns a UTF-8 byte buffer +int32_t rfFReadLine_UTF16BE(FILE* f,char** utf8,uint32_t* byteLength,char* eof) +{ + char buff[RF_OPTION_FGETS_READBYTESN+5]; + int32_t bytesN; + uint32_t *codepoints,charsN,bIndex=0,buffSize=RF_OPTION_FGETS_READBYTESN+5,accum; + char* tempBuff = 0,buffAllocated=false; + + bytesN = rfFgets_UTF16BE(buff,RF_OPTION_FGETS_READBYTESN,f,eof); + accum = (uint32_t)bytesN; + tempBuff = &buff[0];// point the tempBuff to the initial buffer for now + if(bytesN < 0)// error check + { + LOG_ERROR("Failed to read from a Big Endian UTF-16 file",bytesN); + return bytesN; + } + else if(bytesN >= RF_OPTION_FGETS_READBYTESN && (*eof)==false)// if the size does not fit in the buffer and if we did not reach the EOF + { + // allocate the temporary buffer and move the previous buffer's content inside it + buffSize=buffSize*2+5; + RF_MALLOC(tempBuff,buffSize); + memcpy(tempBuff,buff,bytesN); + bIndex=bytesN; + buffAllocated = true; + // keep reading until we have read all until newline or EOF + do + { + bytesN = rfFgets_UTF16BE(tempBuff+bIndex,RF_OPTION_FGETS_READBYTESN,f,eof); + accum+=bytesN; + if(bytesN < 0)// error check + { + LOG_ERROR("Failed to read from a Big Endian UTF-16 file",bytesN); + free(tempBuff); + return bytesN; + } + // realloc to have more space in the buffer for reading if needed + if(accum+RF_OPTION_FGETS_READBYTESN+5 >= buffSize) + { + buffSize=(accum+RF_OPTION_FGETS_READBYTESN+5)*2; + RF_REALLOC(tempBuff,char,buffSize); + } + bIndex += bytesN; + // if the last character was newline break off the loop + if( (*(uint16_t*)(tempBuff+bIndex-2))== (uint16_t)RF_LF) + break; + }while(bytesN >= RF_OPTION_FGETS_READBYTESN && (*eof)==false);// end of reading loop + }// end of size not fitting the initial buffer case + if(bytesN >0)// determine the amount of bytes read + bIndex+=bytesN; + // allocate the codepoints + RF_MALLOC(codepoints,(bIndex+5)*2) + // decode it into codepoints + if(rfUTF16_Decode(tempBuff,&charsN,codepoints)==false) + { + free(codepoints); + if(buffAllocated==true) + free(tempBuff); + LOG_ERROR("Failed to Decode UTF-16 from a File Descriptor",RE_UTF16_INVALID_SEQUENCE); + return RE_UTF16_INVALID_SEQUENCE; + } + // now encode these codepoints into UTF8 + if(((*utf8)=rfUTF8_Encode(codepoints,charsN,byteLength)) == 0) + { + free(codepoints); + if(buffAllocated==true) + free(tempBuff); + LOG_ERROR("Failed to encode the File Descriptor's UTF-16 bytestream to UTF-8",RE_UTF8_ENCODING); + return RE_UTF8_ENCODING;//error + } + // success + free(codepoints); + if(buffAllocated==true) + free(tempBuff); +#ifdef RF_NEWLINE_CRLF + // if the last character was a newline + if(*((*utf8)+(*byteLength)-1) == (char)RF_LF) + { + if(*((*utf8)+(*byteLength)-2) == (char)RF_CR) + { + *((*utf8)+(*byteLength)-2) = RF_LF; + *((*utf8)+(*byteLength)-1) = '\0'; + (*byteLength)-=1; + } + } +#endif + return bIndex; +} +// Reads a Big Endian UTF-32 file descriptor until end of line or EOF is found and returns a UTF-8 byte buffer +int32_t rfFReadLine_UTF32BE(FILE* f,char** utf8,uint32_t* byteLength,char* eof) +{ + char buff[RF_OPTION_FGETS_READBYTESN+7]; + int32_t bytesN; + uint32_t *codepoints,bIndex=0,buffSize=RF_OPTION_FGETS_READBYTESN+7,accum; + char* tempBuff = 0,buffAllocated=false; + bytesN = rfFgets_UTF32BE(buff,RF_OPTION_FGETS_READBYTESN,f,eof); + accum = (uint32_t)bytesN; + tempBuff = &buff[0];// point the tempBuff to the initial buffer for now + if(bytesN < 0)// error check + { + LOG_ERROR("Failed to read from a Big Endian UTF-32 file",bytesN); + return bytesN; + } + else if(bytesN >= RF_OPTION_FGETS_READBYTESN && (*eof)==false)// if the size does not fit in the buffer and if we did not reach the EOF + { + // allocate the temporary buffer and move the previous buffer's content inside it + buffSize=buffSize*2+7; + RF_MALLOC(tempBuff,buffSize); + memcpy(tempBuff,buff,bytesN); + bIndex=bytesN; + buffAllocated = true; + // keep reading until we have read all until newline or EOF + do + { + bytesN = rfFgets_UTF32BE(tempBuff+bIndex,RF_OPTION_FGETS_READBYTESN,f,eof); + accum+=bytesN; + if(bytesN < 0)// error check + { + LOG_ERROR("Failed to read from a Big Endian UTF-16 file",bytesN); + free(tempBuff); + return bytesN; + } + // realloc to have more space in the buffer for reading if needed + if(accum+RF_OPTION_FGETS_READBYTESN+7 >= buffSize) + { + buffSize=(accum+RF_OPTION_FGETS_READBYTESN+7)*2; + RF_REALLOC(tempBuff,char,buffSize); + } + bIndex += bytesN; + // if the last character was newline break off the loop + if( (*(uint32_t*)(tempBuff+bIndex-4))== (uint32_t)RF_LF) + break; + }while(bytesN >= RF_OPTION_FGETS_READBYTESN && (*eof)==false);// end of reading loop + }// end of size not fitting the initial buffer case + if(bytesN >0)//determine the amount of bytes read + bIndex+=bytesN; + // utf-32 is actually codepoints + codepoints = (uint32_t*)tempBuff; + // now encode these codepoints into UTF8 + if(((*utf8)=rfUTF8_Encode(codepoints,bIndex/4,byteLength)) == 0) + { + if(buffAllocated==true) + free(tempBuff); + LOG_ERROR("Failed to encode the File Descriptor's UTF-32 bytestream to UTF-8",RE_UTF8_ENCODING); + return RE_UTF8_ENCODING;// error + } + // success + if(buffAllocated==true) + free(tempBuff); +#ifdef RF_NEWLINE_CRLF + // if the last character was a newline + if(*((*utf8)+(*byteLength)-1) == (char)RF_LF) + { + if(*((*utf8)+(*byteLength)-2) == (char)RF_CR) + { + *((*utf8)+(*byteLength)-2) = RF_LF; + *((*utf8)+(*byteLength)-1) = '\0'; + (*byteLength)-=1; + } + } +#endif + return bIndex; +} +// Reads a Little Endian UTF-32 file descriptor until end of line or EOF is found and returns a UTF-8 byte buffer +int32_t rfFReadLine_UTF32LE(FILE* f,char** utf8,uint32_t* byteLength,char* eof) +{ + char buff[RF_OPTION_FGETS_READBYTESN+7]; + int32_t bytesN; + uint32_t *codepoints,bIndex=0,buffSize=RF_OPTION_FGETS_READBYTESN+7,accum; + char* tempBuff = 0,buffAllocated=false; + bytesN = rfFgets_UTF32LE(buff,RF_OPTION_FGETS_READBYTESN,f,eof); + accum = (uint32_t) bytesN; + tempBuff = &buff[0];// point the tempBuff to the initial buffer for now + if(bytesN < 0)// error check + { + LOG_ERROR("Failed to read from a Little Endian UTF-32 file",bytesN); + return bytesN; + } + else if(bytesN >= RF_OPTION_FGETS_READBYTESN && (*eof)==false)// if the size does not fit in the buffer and if we did not reach the EOF + { + // allocate the temporary buffer and move the previous buffer's content inside it + buffSize=buffSize*2+7; + RF_MALLOC(tempBuff,buffSize); + memcpy(tempBuff,buff,bytesN); + bIndex=bytesN; + buffAllocated = true; + // keep reading until we have read all until newline or EOF + do + { + bytesN = rfFgets_UTF32LE(tempBuff+bIndex,RF_OPTION_FGETS_READBYTESN,f,eof); + accum +=bytesN; + if(bytesN < 0)// error check + { + LOG_ERROR("Failed to read from a Little Endian UTF-16 file",bytesN); + free(tempBuff); + return bytesN; + } + // realloc to have more space in the buffer for reading if needed + if(accum+RF_OPTION_FGETS_READBYTESN+7 >= buffSize) + { + buffSize=(accum+RF_OPTION_FGETS_READBYTESN+7)*2; + RF_REALLOC(tempBuff,char,buffSize); + } + bIndex += bytesN; + // if the last character was newline break off the loop + if( (*(uint32_t*)(tempBuff+bIndex-4))== (uint32_t)RF_LF) + break; + }while(bytesN >= RF_OPTION_FGETS_READBYTESN && (*eof)==false);// end of reading loop + }// end of size not fitting the initial buffer case + if(bytesN >0)// determine the amount of bytes read + bIndex+=bytesN; + // utf-32 is actually codepoints + codepoints = (uint32_t*)tempBuff; + // now encode these codepoints into UTF8 + if(((*utf8)=rfUTF8_Encode(codepoints,bIndex/4,byteLength)) == 0) + { + if(buffAllocated==true) + free(tempBuff); + LOG_ERROR("Failed to encode the File Descriptor's UTF-32 bytestream to UTF-8",RE_UTF8_ENCODING); + return RE_UTF8_ENCODING;// error + } + // success + if(buffAllocated==true) + free(tempBuff); +#ifdef RF_NEWLINE_CRLF + // if the last character was a newline + if(*((*utf8)+(*byteLength)-1) == (char)RF_LF) + { + if(*((*utf8)+(*byteLength)-2) == (char)RF_CR) + { + *((*utf8)+(*byteLength)-2) = RF_LF; + *((*utf8)+(*byteLength)-1) = '\0'; + (*byteLength)-=1; + } + } +#endif + return bIndex; +} + +// This is a function that's similar to c library fgets but it also returns the number of bytes read and works for UTF-32 encoded files +int32_t rfFgets_UTF32BE(char* buff,uint32_t num,FILE* f,char* eofReached) +{ + uint32_t size,c; + int32_t error; + // initialization + *eofReached = false; + size = 0; + // if end of file or end of line is not found, keep reading + do{ + if((error=rfFgetc_UTF32BE(f,(uint32_t*)(buff+size))) != RF_SUCCESS) + { + if(error == RE_FILE_EOF) + { + break;// EOF found + *eofReached = true; + } + LOG_ERROR("Reading error while reading from a Big Endian UTF-32 file",error); + return error; + } + size+= 4; + // if we have read the number of characters requested by the function + if(size >= num) + { + break; + } + // get the last character read + c = *(uint32_t*)(buff+size-4); + }while(c != (uint32_t)EOF && !RF_HEXEQ_UI(c,RF_LF)); + // null terminate the buffer for UTF32 + buff[size] = buff[size+1] = buff[size+2] = buff[size+3] = '\0'; + // finally check yet again for end of file right after the new line + if((error=rfFgetc_UTF32BE(f,&c))!=RF_SUCCESS) + { + if(error == RE_FILE_EOF) + {// EOF + *eofReached = true; + } + else + { + LOG_ERROR("Reading error while reading from a Big Endian UTF-32 file",error); + return error; + } + } + else// undo the peek ahead of the file pointer + fseek(f,-4,SEEK_CUR); + return size; +} +// This is a function that's similar to c library fgets but it also returns the number of bytes read and works for UTF-32 encoded files +int32_t rfFgets_UTF32LE(char* buff,uint32_t num,FILE* f,char* eofReached) +{ + uint32_t size,c; + int32_t error; + // initialization + *eofReached = false; + size = 0; + // if end of file or end of line is not found, keep reading + do{ + if((error=rfFgetc_UTF32LE(f,(uint32_t*)(buff+size))) != RF_SUCCESS) + { + if(error == RE_FILE_EOF) + { + break;// EOF found + *eofReached = true; + } + LOG_ERROR("Reading error while reading from a Little Endian UTF-32 file",error); + return error; + } + size+= 4; + // if we have read the number of characters requested by the function + if(size >= num) + { + break; + } + // get the last character read + c = *(uint32_t*)(buff+size-4); + }while(c !=(uint32_t) EOF && !RF_HEXEQ_UI(c,RF_LF)); + // null terminate the buffer for UTF32 + buff[size] = buff[size+1] = buff[size+2] = buff[size+3] = '\0'; + // finally check yet again for end of file right after the new line + if((error=rfFgetc_UTF32LE(f,&c))!=RF_SUCCESS) + { + if(error == RE_FILE_EOF) + {// EOF + *eofReached = true; + } + else + { + LOG_ERROR("Reading error while reading from a Little Endian UTF-32 file",error); + return error; + } + } + else// undo the peek ahead of the file pointer + fseek(f,-4,SEEK_CUR); + return size; +} +// Gets a number of bytes from a BIG endian UTF-16 file descriptor +int32_t rfFgets_UTF16BE(char* buff,uint32_t num,FILE* f,char* eofReached) +{ + uint32_t size,c; + int32_t bytesN; + // initialization + *eofReached = false; + size = 0; + // if end of file or end of line is not found, keep reading + do{ + bytesN = rfFgetc_UTF16BE(f,(uint32_t*)(buff+size),false); + // error check + if(bytesN < 0) + { + if(bytesN == RE_FILE_EOF) + { + break;// EOF found + *eofReached = true; + } + else + return bytesN; + } + size+= bytesN; + // if we have read the number of characters requested by the function + if(size >= num) + { + break; + } + // get the last character read + c = *(uint32_t*)(buff+size-bytesN); + }while(c !=(uint32_t) EOF && !RF_HEXEQ_UI(c,RF_LF)); + // null terminate the buffer for UTF16 + buff[size] = buff[size+1] = '\0'; + // finally check yet again for end of file right after the new line + bytesN = rfFgetc_UTF16BE(f,&c,false); + if(bytesN < 0) + { + if(bytesN == RE_FILE_EOF) + {// EOF + *eofReached = true; + } + else// error + return bytesN; + } + else// undo the peek ahead of the file pointer + fseek(f,-bytesN,SEEK_CUR); + return size; +} +// Gets a number of bytes from a Little endian UTF-16 file descriptor +int32_t rfFgets_UTF16LE(char* buff,uint32_t num,FILE* f,char* eofReached) +{ + uint32_t size,c; + int32_t bytesN; + // initialization + *eofReached = false; + size = 0; + // if end of file or end of line is not found, keep reading + do{ + bytesN = rfFgetc_UTF16LE(f,(uint32_t*)(buff+size),false); + // error check + if(bytesN < 0) + { + if(bytesN == RE_FILE_EOF) + { + break;// EOF found + *eofReached = true; + } + else + return bytesN; + } + size+= bytesN; + // if we have read the number of characters requested by the function + if(size >= num) + { + break; + } + // get the last character read + c = *(uint32_t*)(buff+size-bytesN); + }while(c !=(uint32_t) EOF && !RF_HEXEQ_UI(c,RF_LF)); + // null terminate the buffer for UTF16 + buff[size] = buff[size+1] = '\0'; + // finally check yet again for end of file right after the new line + bytesN = rfFgetc_UTF16LE(f,&c,false); + if(bytesN < 0) + { + if(bytesN == RE_FILE_EOF) + {// EOF + *eofReached = true; + } + else// error + return bytesN; + } + else// undo the peek ahead of the file pointer + fseek(f,-bytesN,SEEK_CUR); + + return size; +} + +// Gets a number of bytes from a UTF-8 file descriptor +int32_t rfFgets_UTF8(char* buff,uint32_t num,FILE* f,char* eofReached) +{ + uint32_t size,c; + int32_t bytesN; + // initialization + *eofReached = false; + size = 0; + // if end of file or end of line is not found, keep reading + do{ + bytesN = rfFgetc_UTF8(f,(uint32_t*)(buff+size),false); + // error check + if(bytesN < 0) + { + if(bytesN == RE_FILE_EOF) + { + break;// EOF found + *eofReached = true; + } + else + return bytesN; + } + size+= bytesN; + // if we have read the number of characters requested by the function + if(size >= num) + { + break; + } + // get the last character + c = *(uint32_t*)(buff+size-bytesN); + }while(c !=(uint32_t) EOF && !RF_HEXEQ_UI(c,RF_LF)); + // null terminate the buffer for UTF8 + buff[size] = '\0'; + // finally check yet again for end of file right after the new line + if( RF_HEXEQ_C(fgetc(f),EOF)) + {// check for error + if(ferror(f) != 0) + { + LOG_ERROR("During reading a UTF-8 file there was a read error",RE_FILE_READ); + return RE_FILE_READ; + } + // if not it's end of file, so note it and take the pointer back by 1 + *eofReached = true; + }// undo the peek ahead of the file pointer + else + fseek(f,-1,SEEK_CUR); + return size; +} +// Gets a unicode character from a UTF-8 file descriptor +int32_t rfFgetc_UTF8(FILE* f,uint32_t *ret,char cp) +{ + char c,c2,c3,c4; + if( (c = fgetc(f)) == EOF) + { + i_READ_CHECK(f,"While reading a UTF-8 character from the stream") + else + return RE_FILE_EOF; + } + // if the lead bit of the byte is 0 then range is : U+0000 to U+0007F (1 byte) + if( ((c & 0x80)>>7) == 0 ) + { + /// success + if(cp == true) + *ret = c; + else + { + *ret = 0; + char* cc = (char*) ret; + cc[0] = c; + } + return 1; + } + else// we need more bytes + { + // if the leading bits are in the form of 0b110xxxxx then range is: U+0080 to U+07FF (2 bytes) + if( RF_HEXEQ_C( ( (~(c ^ 0xC0))>>5), 0x7) ) + { + // also remember bytes 0xC0 and 0xC1 are invalid and could possibly be found in a starting byte of this type so check for them here + if( RF_HEXEQ_C(c,0xC0) || RF_HEXEQ_C(c,0xC1)) + { + LOG_ERROR("While decoding a UTF-8 file byte stream, an invalid byte was encountered",RE_UTF8_INVALID_SEQUENCE_INVALID_BYTE); + return RE_UTF8_INVALID_SEQUENCE_INVALID_BYTE; + } + // so now read the next byte + if( (c2 = fgetc(f)) == EOF) + { + i_READ_CHECK(f,"While reading a UTF-8 character from a file stream") + else + { + LOG_ERROR("While decoding a UTF-8 file byte stream, EOF was encountered abruplty in-between bytes",RE_UTF8_INVALID_SEQUENCE_END); + return RE_FILE_EOF; + } + } + // if this second byte is NOT a continuation byte + if( !rfUTF8_IsContinuationByte(c2)) + { + LOG_ERROR("While decoding a UTF-8 file byte stream, and expecting a continuation byte, one was not found",RE_UTF8_INVALID_SEQUENCE_CONBYTE); + return RE_UTF8_INVALID_SEQUENCE_CONBYTE; + } + /// success + if(cp == true)// return decoded codepoint + { + *ret = 0; + // from the second byte take the first 6 bits + *ret = (c2 & 0x3F) ; + // from the first byte take the first 5 bits and put them in the start + *ret |= ((c & 0x1F) << 6); + } + else + { + *ret = 0; + char* cc = (char*)ret; + cc[0] = c; cc[1] = c2; + } + return 2; + + }// end of the 2 bytes case + // if the leading bits are in the form of 0b1110xxxx then range is U+0800 to U+FFFF (3 bytes) + else if( RF_HEXEQ_C( ( (~(c ^ 0xE0))>>4),0xF)) + { + // so now read the next 2 bytes + if( (c2 = fgetc(f)) == EOF) + { + i_READ_CHECK(f,"While reading a UTF-8 character from a file stream") + else + { + LOG_ERROR("While decoding a UTF-8 file byte stream, EOF was encountered abruplty in-between bytes",RE_UTF8_INVALID_SEQUENCE_END); + return RE_FILE_EOF; + } + } + if( (c3 = fgetc(f)) == EOF) + { + i_READ_CHECK(f,"While reading a UTF-8 character from a file stream") + else + { + LOG_ERROR("While decoding a UTF-8 file byte stream, EOF was encountered abruplty in-between bytes",RE_UTF8_INVALID_SEQUENCE_END); + return RE_FILE_EOF; + } + } + // if the subsequent bytes are NOT continuation bytes + if( !rfUTF8_IsContinuationByte(c2) || !rfUTF8_IsContinuationByte(c3)) + { + LOG_ERROR("While decoding a UTF-8 file byte stream, and expecting a continuation byte, one was not found",RE_UTF8_INVALID_SEQUENCE_CONBYTE); + return RE_UTF8_INVALID_SEQUENCE_CONBYTE; + } + /// success + if(cp == true)// if we need to decode the codepoint + { + *ret = 0; + // from the third byte take the first 6 bits + *ret = (c3 & 0x3F) ; + // from the second byte take the first 6 bits and put them to the left of the previous 6 bits + *ret |= ((c2 & 0x3F) << 6); + // from the first byte take the first 4 bits and put them to the left of the previous 6 bits + *ret |= ((c & 0xF) << 12); + } + else + { + *ret = 0; + char* cc = (char*)ret; + cc[0] = c; cc[1] = c2; cc[2] = c3; + } + return 3; + }// end of 3 bytes case + // if the leading bits are in the form of 0b11110xxx then range is U+010000 to U+10FFFF (4 bytes) + else if(RF_HEXEQ_C( ( (~(c ^ 0xF0))>>3), 0x1F)) + { + // in this type of starting byte a number of invalid bytes can be encountered. We have to check for them. + if(RF_HEXGE_C(c,0xBF)) //invalid byte value are from 0xBF to 0xFF + { + LOG_ERROR("While decoding a UTF-8 file byte stream, an invalid byte was encountered",RE_UTF8_INVALID_SEQUENCE_INVALID_BYTE); + return RE_UTF8_INVALID_SEQUENCE_INVALID_BYTE; + } + // so now read the next 3 bytes + if( (c2 = fgetc(f)) == EOF) + { + i_READ_CHECK(f,"While reading a UTF-8 character from a file stream") + else + { + LOG_ERROR("While decoding a UTF-8 file byte stream, EOF was encountered abruplty in-between bytes",RE_UTF8_INVALID_SEQUENCE_END); + return RE_FILE_EOF; + } + } + if( (c3 = fgetc(f)) == EOF) + { + i_READ_CHECK(f,"While reading a UTF-8 character from a file stream") + else + { + LOG_ERROR("While decoding a UTF-8 file byte stream, EOF was encountered abruplty in-between bytes",RE_UTF8_INVALID_SEQUENCE_END); + return RE_FILE_EOF; + } + } + if( (c4 = fgetc(f)) == EOF) + { + i_READ_CHECK(f,"While reading a UTF-8 character from a file stream") + else + { + LOG_ERROR("While decoding a UTF-8 file byte stream, EOF was encountered abruplty in-between bytes",RE_UTF8_INVALID_SEQUENCE_END); + return RE_FILE_EOF; + } + } + // if the subsequent bytes are NOT continuation bytes + if( !rfUTF8_IsContinuationByte(c2) || !rfUTF8_IsContinuationByte(c3) || !rfUTF8_IsContinuationByte(c4)) + { + LOG_ERROR("While decoding a UTF-8 file byte stream, and expecting a continuation byte, one was not found",RE_UTF8_INVALID_SEQUENCE_CONBYTE); + return RE_UTF8_INVALID_SEQUENCE_CONBYTE; + } + /// success + if(cp == true) //if we need to decode the codepoint + { + *ret = 0; + // from the fourth byte take the first 6 bits + *ret = (c4 & 0x3F) ; + // from the third byte take the first 6 bits and put them to the left of the previous 6 bits + *ret |= ((c3 & 0x3F) << 6); + // from the second byte take the first 6 bits and put them to the left of the previous 6 bits + *ret |= ((c2 & 0x3F) << 12); + // from the first byte take the first 3 bits and put them to the left of the previous 6 bits + *ret |= ((c & 0x7) << 18); + } + else + { + *ret = 0; + char* cc = (char*)ret; + cc[0] = c; cc[1] = c2; cc[2] = c3; cc[3]=c4; + } + return 4; + }// end of 4 bytes case + }// end of needing more than 1 byte + + // if we get here means the 1st byte belonged to none of the 4 cases + LOG_ERROR("While decoding a UTF-8 file byte stream, the first byte of a character was invalid UTF-8",RE_UTF8_INVALID_SEQUENCE_INVALID_BYTE); + return RE_UTF8_INVALID_SEQUENCE_INVALID_BYTE; +} + +// Gets a unicode character from a Big Endian UTF-16 file descriptor +int32_t rfFgetc_UTF16BE(FILE* f,uint32_t *c,char cp) +{ + char swapE=false; + uint16_t v1,v2; + // check if we need to be swapping + if(rfUTILS_Endianess() == RF_LITTLE_ENDIAN) + swapE = true; + // read the first 2 bytes + if(fread(&v1,2,1,f) != 1) + { + i_READ_CHECK(f,"While reading a UTF-16 from a Big Endian File stream") + else + return RE_FILE_EOF; + } + if(swapE)// swap endianess if needed + rfUTILS_SwapEndianUS(&v1); + /* If the value is in the surrogate area */ + if(RF_HEXGE_US(v1,0xD800) && RF_HEXLE_US(v1,0xDFFF)) + { + if(RF_HEXL_US(v1,0xD800) || RF_HEXG_US(v1,0xDBFF)) + { + LOG_ERROR("While reading a Big endian UTF-16 file stream the first byte encountered held an illegal value",RE_UTF16_INVALID_SEQUENCE); + return RE_UTF16_INVALID_SEQUENCE; + } + // then we also need to read its surrogate pair + if(fread(&v2,2,1,f) != 1) + { + i_READ_CHECK(f,"While reading a UTF-16 from a Big Endian File stream") + else + { + LOG_ERROR("While decoding a UTF-16 Big Endian file byte stream, EOF was encountered abruplty when expecting a surrogate pair",RE_UTF16_NO_SURRPAIR); + return RE_FILE_EOF; + } + } + if(swapE)// swap endianess if needed + rfUTILS_SwapEndianUS(&v2); + if(RF_HEXL_US(v2,0xDC00) || RF_HEXG_US(v2,0xDFFF)) + { + LOG_ERROR("While reading a Big endian UTF-16 file stream the surrogate pair encountered held an illegal value",RE_UTF16_INVALID_SEQUENCE); + return RE_UTF16_INVALID_SEQUENCE; + } + if(cp == true)// if the user wants the decoded codepoint + { + *c = 0; + *c = v2&0x3ff; + *c |= (10< +#include + +#ifdef __cplusplus +extern "C" +{// opening bracket for calling from C++ +#endif + +// New line feed +#define RF_LF 0xA +// Carriage Return +#define RF_CR 0xD + +#ifdef REFU_WIN32_VERSION + #define i_PLUSB_WIN32 "b" +#else + #define i_PLUSB_WIN32 "" +#endif + +// This is the type that represents the file offset +#ifdef _MSC_VER +typedef __int64 foff_rft; +#else +#include +typedef off64_t foff_rft; +#endif +///Fseek and Ftelll definitions +#ifdef _MSC_VER + #define rfFseek(i_FILE_,i_OFFSET_,i_WHENCE_) _fseeki64(i_FILE_,i_OFFSET_,i_WHENCE_) + #define rfFtell(i_FILE_) _ftelli64(i_FILE_) +#else + #define rfFseek(i_FILE_,i_OFFSET_,i_WHENCE_) fseeko64(i_FILE_,i_OFFSET_,i_WHENCE_) + #define rfFtell(i_FILE_) ftello64(i_FILE_) +#endif + +/** +** @defgroup RF_IOGRP I/O +** @addtogroup RF_IOGRP +** @{ +**/ + +// @brief Reads a UTF-8 file descriptor until end of line or EOF is found and returns a UTF-8 byte buffer +// +// The file descriptor at @c f must have been opened in binary and not text mode. That means that if under +// Windows make sure to call fopen with "wb", "rb" e.t.c. instead of the simple "w", "r" e.t.c. since the initial +// default value under Windows is text mode. Alternatively you can set the initial value using _get_fmode() and +// _set_fmode(). For more information take a look at the msdn pages here: +// http://msdn.microsoft.com/en-us/library/ktss1a9b.aspx +// +// When the compile flag @c RF_NEWLINE_CRLF is defined (the default case at Windows) then this function +// shall not be adding any CR character that is found in the file behind a newline character since this is +// the Windows line ending scheme. Beware though that the returned read bytes value shall still count the CR character inside. +// +// @param[in] f The file descriptor to read +// @param[out] utf8 Give here a refence to an unitialized char* that will be allocated inside the function +// and contain the utf8 byte buffer. Needs to be freed by the caller explicitly later +// @param[out] byteLength Give an @c uint32_t here to receive the length of the @c utf8 buffer in bytes +// @param[out] bufferSize Give an @c uint32_t here to receive the capacity of the @c utf8 buffer in bytes +// @param[out] eof Pass a pointer to a char to receive a true or false value in case the end of file +// with reading this line +// @return Returns either a positive number for success that represents the number of bytes read from @c f and and error in case something goes wrong. +// The possible errors to return are the same as rfFgets_UTF8() +i_DECLIMEX_ int32_t rfFReadLine_UTF8(FILE* f,char** utf8,uint32_t* byteLength,uint32_t* bufferSize,char* eof); +// @brief Reads a Big Endian UTF-16 file descriptor until end of line or EOF is found and returns a UTF-8 byte buffer +// +// The file descriptor at @c f must have been opened in binary and not text mode. That means that if under +// Windows make sure to call fopen with "wb", "rb" e.t.c. instead of the simple "w", "r" e.t.c. since the initial +// default value under Windows is text mode. Alternatively you can set the initial value using _get_fmode() and +// _set_fmode(). For more information take a look at the msdn pages here: +// http://msdn.microsoft.com/en-us/library/ktss1a9b.aspx +// +// When the compile flag @c RF_NEWLINE_CRLF is defined (the default case at Windows) then this function +// shall not be adding any CR character that is found in the file behind a newline character since this is +// the Windows line ending scheme. Beware though that the returned read bytes value shall still count the CR character inside. +// +// @param[in] f The file descriptor to read +// @param[out] utf8 Give here a refence to an unitialized char* that will be allocated inside the function +// and contain the utf8 byte buffer. Needs to be freed by the caller explicitly later +// @param[out] byteLength Give an @c uint32_t here to receive the length of the @c utf8 buffer in bytes +// @param[out] eof Pass a pointer to a char to receive a true or false value in case the end of file +// with reading this line +// @return Returns either a positive number for success that represents the number of bytes read from @c f and and error in case something goes wrong. +// + Any error that can be returned by @ref rfFgets_UTF16BE() +// + @c RE_UTF16_INVALID_SEQUENCE: Failed to decode the UTF-16 byte stream of the file descriptor +// + @c RE_UTF8_ENCODING: Failed to encode the UTF-16 of the file descriptor into UTF-8 +i_DECLIMEX_ int32_t rfFReadLine_UTF16BE(FILE* f,char** utf8,uint32_t* byteLength,char* eof); +// @brief Reads a Little Endian UTF-16 file descriptor until end of line or EOF is found and returns a UTF-8 byte buffer +// +// The file descriptor at @c f must have been opened in binary and not text mode. That means that if under +// Windows make sure to call fopen with "wb", "rb" e.t.c. instead of the simple "w", "r" e.t.c. since the initial +// default value under Windows is text mode. Alternatively you can set the initial value using _get_fmode() and +// _set_fmode(). For more information take a look at the msdn pages here: +// http://msdn.microsoft.com/en-us/library/ktss1a9b.aspx +// +// When the compile flag @c RF_NEWLINE_CRLF is defined (the default case at Windows) then this function +// shall not be adding any CR character that is found in the file behind a newline character since this is +// the Windows line ending scheme. Beware though that the returned read bytes value shall still count the CR character inside. +// +// @param[in] f The file descriptor to read +// @param[out] utf8 Give here a refence to an unitialized char* that will be allocated inside the function +// and contain the utf8 byte buffer. Needs to be freed by the caller explicitly later +// @param[out] byteLength Give an @c uint32_t here to receive the length of the @c utf8 buffer in bytes +// @param[out] eof Pass a pointer to a char to receive a true or false value in case the end of file +// with reading this line +// @return Returns either a positive number for success that represents the number of bytes read from @c f and and error in case something goes wrong. +// + Any error that can be returned by @ref rfFgets_UTF16LE() +// + @c RE_UTF16_INVALID_SEQUENCE: Failed to decode the UTF-16 byte stream of the file descriptor +// + @c RE_UTF8_ENCODING: Failed to encode the UTF-16 of the file descriptor into UTF-8 +i_DECLIMEX_ int32_t rfFReadLine_UTF16LE(FILE* f,char** utf8,uint32_t* byteLength,char* eof); + +// @brief Reads a Big Endian UTF-32 file descriptor until end of line or EOF is found and returns a UTF-8 byte buffer +// +// The file descriptor at @c f must have been opened in binary and not text mode. That means that if under +// Windows make sure to call fopen with "wb", "rb" e.t.c. instead of the simple "w", "r" e.t.c. since the initial +// default value under Windows is text mode. Alternatively you can set the initial value using _get_fmode() and +// _set_fmode(). For more information take a look at the msdn pages here: +// http://msdn.microsoft.com/en-us/library/ktss1a9b.aspx +// +// When the compile flag @c RF_NEWLINE_CRLF is defined (the default case at Windows) then this function +// shall not be adding any CR character that is found in the file behind a newline character since this is +// the Windows line ending scheme. Beware though that the returned read bytes value shall still count the CR character inside. +// +// @param[in] f The file descriptor to read +// @param[out] utf8 Give here a refence to an unitialized char* that will be allocated inside the function +// and contain the utf8 byte buffer. Needs to be freed by the caller explicitly later +// @param[out] byteLength Give an @c uint32_t here to receive the length of the @c utf8 buffer in bytes +// @param[out] eof Pass a pointer to a char to receive a true or false value in case the end of file +// with reading this line +// @return Returns either a positive number for success that represents the number of bytes read from @c f and and error in case something goes wrong. +// + Any error that can be returned by @ref rfFgets_UTF32BE() +// + @c RE_UTF8_ENCODING: Failed to encode the UTF-16 of the file descriptor into UTF-8 +i_DECLIMEX_ int32_t rfFReadLine_UTF32BE(FILE* f,char** utf8,uint32_t* byteLength,char* eof); +// @brief Reads a Little Endian UTF-32 file descriptor until end of line or EOF is found and returns a UTF-8 byte buffer +// +// The file descriptor at @c f must have been opened in binary and not text mode. That means that if under +// Windows make sure to call fopen with "wb", "rb" e.t.c. instead of the simple "w", "r" e.t.c. since the initial +// default value under Windows is text mode. Alternatively you can set the initial value using _get_fmode() and +// _set_fmode(). For more information take a look at the msdn pages here: +// http://msdn.microsoft.com/en-us/library/ktss1a9b.aspx +// +// When the compile flag @c RF_NEWLINE_CRLF is defined (the default case at Windows) then this function +// shall not be adding any CR character that is found in the file behind a newline character since this is +// the Windows line ending scheme. Beware though that the returned read bytes value shall still count the CR character inside. +// +// @param[in] f The file descriptor to read +// @param[out] utf8 Give here a refence to an unitialized char* that will be allocated inside the function +// and contain the utf8 byte buffer. Needs to be freed by the caller explicitly later +// @param[out] byteLength Give an @c uint32_t here to receive the length of the @c utf8 buffer in bytes +// @param[out] eof Pass a pointer to a char to receive a true or false value in case the end of file +// with reading this line +// @return Returns either a positive number for success that represents the number of bytes read from @c f and and error in case something goes wrong. +// + Any error that can be returned by @ref rfFgets_UTF32LE() +// + @c RE_UTF8_ENCODING: Failed to encode the UTF-16 of the file descriptor into UTF-8 +i_DECLIMEX_ int32_t rfFReadLine_UTF32LE(FILE* f,char** utf8,uint32_t* byteLength,char* eof); + +// @brief Gets a number of bytes from a BIG endian UTF-32 file descriptor +// +// This is a function that's similar to c library fgets but it also returns the number of bytes read. Reads in from the file until @c num bytes +// have been read or new line or EOF character has been encountered. +// +// The function will read until @c num characters are read and if @c num +// would take us to the middle of a UTF32 character then the next character shall also be read +// and the function will return the number of bytes read. +// Since the function null terminates the buffer the given @c buff needs to be of at least +// @c num+7 size to cater for the worst case. +// +// The final bytestream stored inside @c buff is in the endianess of the system. +// +// If right after the last character read comes the EOF, the function +// shall detect so and assign @c true to @c eof. +// +// In Windows where file endings are in the form of 2 bytes CR-LF (Carriage return - NewLine) this function +// shall just ignore the carriage returns and not return it inside the return buffer at @c buff. +// +// The file descriptor at @c f must have been opened in binary and not text mode. That means that if under +// Windows make sure to call fopen with "wb", "rb" e.t.c. instead of the simple "w", "r" e.t.c. since the initial +// default value under Windows is text mode. Alternatively you can set the initial value using _get_fmode() and +// _set_fmode(). For more information take a look at the msdn pages here: +// http://msdn.microsoft.com/en-us/library/ktss1a9b.aspx +// +// @param[in] buff A buffer to be filled with the contents of the file. Should be of size at least @c num+7 +// @param[in] num The maximum number of bytes to read from within the file NOT including the null terminating character(which in itelf is 4 bytes). Should be a multiple of 4 +// @param[in] f A valid FILE descriptor from which to read the bytes +// @param[out] eof Pass a reference to a char to receive a true/false value for whether EOF has been reached. +// @return Returns the actual number of bytes read or an error if there was a problem. +// The possible errors are: +// + @c RE_FILE_READ: If during reading the file there was an unknown read error +// + @c RE_FILE_READ_BLOCK: If the read operation failed due to the file descriptor being occupied by another thread +// + @c RE_FILE_MODE: If during reading the file the file descriptor's mode was not correctly set for reading +// + @c RE_FILE_POS_OVERFLOW: If during reading, the current file position can't be represented by the system +// + @c RE_INTERRUPT: If during reading, there was a system interrupt +// + @c RE_FILE_IO: If there was a physical I/O error +// + @c RE_FILE_NOSPACE: If reading failed due to insufficient storage space +i_DECLIMEX_ int32_t rfFgets_UTF32BE(char* buff,uint32_t num,FILE* f,char* eof); +// @brief Gets a number of bytes from a Little endian UTF-32 file descriptor +// +// This is a function that's similar to c library fgets but it also returns the number of bytes read. Reads in from the file until @c num bytes +// have been read or new line or EOF character has been encountered. +// +// The function will read until @c num characters are read and if @c num +// would take us to the middle of a UTF32 character then the next character shall also be read +// and the function will return the number of bytes read. +// Since the function null terminates the buffer the given @c buff needs to be of at least +// @c num+7 size to cater for the worst case. +// +// The final bytestream stored inside @c buff is in the endianess of the system. +// +// If right after the last character read comes the EOF, the function +// shall detect so and assign @c true to @c eof. +// +// In Windows where file endings are in the form of 2 bytes CR-LF (Carriage return - NewLine) this function +// shall just ignore the carriage returns and not return it inside the return buffer at @c buff. +// +// The file descriptor at @c f must have been opened in binary and not text mode. That means that if under +// Windows make sure to call fopen with "wb", "rb" e.t.c. instead of the simple "w", "r" e.t.c. since the initial +// default value under Windows is text mode. Alternatively you can set the initial value using _get_fmode() and +// _set_fmode(). For more information take a look at the msdn pages here: +// http://msdn.microsoft.com/en-us/library/ktss1a9b.aspx +// +// @param[in] buff A buffer to be filled with the contents of the file. Should be of size at least @c num+7 +// @param[in] num The maximum number of bytes to read from within the file NOT including the null terminating character(which in itelf is 4 bytes). Should be a multiple of 4 +// @param[in] f A valid FILE descriptor from which to read the bytes +// @param[out] eof Pass a reference to a char to receive a true/false value for whether EOF has been reached. +// @return Returns the actual number of bytes read or an error if there was a problem. +// The possible errors are: +// + @c RE_FILE_READ: If during reading the file there was an unknown read error +// + @c RE_FILE_READ_BLOCK: If the read operation failed due to the file descriptor being occupied by another thread +// + @c RE_FILE_MODE: If during reading the file the file descriptor's mode was not correctly set for reading +// + @c RE_FILE_POS_OVERFLOW: If during reading, the current file position can't be represented by the system +// + @c RE_INTERRUPT: If during reading, there was a system interrupt +// + @c RE_FILE_IO: If there was a physical I/O error +// + @c RE_FILE_NOSPACE: If reading failed due to insufficient storage space +i_DECLIMEX_ int32_t rfFgets_UTF32LE(char* buff,uint32_t num,FILE* f,char* eof); + +// @brief Gets a number of bytes from a BIG endian UTF-16 file descriptor +// +// This is a function that's similar to c library fgets but it also returns the number of bytes read. Reads in from the file until @c num bytes +// have been read or new line or EOF character has been encountered. +// +// The function will read until @c num characters are read and if @c num +// would take us to the middle of a UTF16 character then the next character shall also be read +// and the function will return the number of bytes read. +// Since the function null terminates the buffer the given @c buff needs to be of at least +// @c num+5 size to cater for the worst case. +// +// The final bytestream stored inside @c buff is in the endianess of the system. +// +// If right after the last character read comes the EOF, the function +// shall detect so and assign @c true to @c eof. +// +// In Windows where file endings are in the form of 2 bytes CR-LF (Carriage return - NewLine) this function +// shall just ignore the carriage returns and not return it inside the return buffer at @c buff. +// +// The file descriptor at @c f must have been opened in binary and not text mode. That means that if under +// Windows make sure to call fopen with "wb", "rb" e.t.c. instead of the simple "w", "r" e.t.c. since the initial +// default value under Windows is text mode. Alternatively you can set the initial value using _get_fmode() and +// _set_fmode(). For more information take a look at the msdn pages here: +// http://msdn.microsoft.com/en-us/library/ktss1a9b.aspx +// +// @param[in] buff A buffer to be filled with the contents of the file. Should be of size at least @c num+5 +// @param[in] num The maximum number of bytes to read from within the file NOT including the null terminating character(which in itelf is 2 bytes). Should be a multiple of 2 +// @param[in] f A valid FILE descriptor from which to read the bytes +// @param[out] eof Pass a reference to a char to receive a true/false value for whether EOF has been reached. +// @return Returns the actual number of bytes read or an error if there was a problem. +// The possible errors are: +// + @c RE_FILE_READ: If during reading the file there was an unknown read error +// + @c RE_FILE_READ_BLOCK: If the read operation failed due to the file descriptor being occupied by another thread +// + @c RE_FILE_MODE: If during reading the file the file descriptor's mode was not correctly set for reading +// + @c RE_FILE_POS_OVERFLOW: If during reading, the current file position can't be represented by the system +// + @c RE_INTERRUPT: If during reading, there was a system interrupt +// + @c RE_FILE_IO: If there was a physical I/O error +// + @c RE_FILE_NOSPACE: If reading failed due to insufficient storage space +i_DECLIMEX_ int32_t rfFgets_UTF16BE(char* buff,uint32_t num,FILE* f,char* eof); +// @brief Gets a number of bytes from a Little endian UTF-16 file descriptor +// +// This is a function that's similar to c library fgets but it also returns the number of bytes read. Reads in from the file until @c num bytes +// have been read or new line or EOF character has been encountered. +// +// The function will read until @c num characters are read and if @c num +// would take us to the middle of a UTF16 character then the next character shall also be read +// and the function will return the number of bytes read. +// Since the function null terminates the buffer the given @c buff needs to be of at least +// @c num+5 size to cater for the worst case. +// +// The final bytestream stored inside @c buff is in the endianess of the system. +// +// If right after the last character read comes the EOF, the function +// shall detect so and assign @c true to @c eof. +// +// In Windows where file endings are in the form of 2 bytes CR-LF (Carriage return - NewLine) this function +// shall just ignore the carriage returns and not return it inside the return buffer at @c buff. +// +// The file descriptor at @c f must have been opened in binary and not text mode. That means that if under +// Windows make sure to call fopen with "wb", "rb" e.t.c. instead of the simple "w", "r" e.t.c. since the initial +// default value under Windows is text mode. Alternatively you can set the initial value using _get_fmode() and +// _set_fmode(). For more information take a look at the msdn pages here: +// http://msdn.microsoft.com/en-us/library/ktss1a9b.aspx +// +// @param[in] buff A buffer to be filled with the contents of the file. Should be of size at least @c num+2 +// @param[in] num The maximum number of bytes to read from within the file NOT including the null terminating character(which in itelf is 2 bytes). Should be a multiple of 2 +// @param[in] f A valid FILE descriptor from which to read the bytes +// @param[out] eof Pass a reference to a char to receive a true/false value for whether EOF has been reached. +// @return Returns the actual number of bytes read or an error if there was a problem. +// The possible errors are: +// + @c RE_FILE_READ: If during reading the file there was an unknown read error +// + @c RE_FILE_READ_BLOCK: If the read operation failed due to the file descriptor being occupied by another thread +// + @c RE_FILE_MODE: If during reading the file the file descriptor's mode was not correctly set for reading +// + @c RE_FILE_POS_OVERFLOW: If during reading, the current file position can't be represented by the system +// + @c RE_INTERRUPT: If during reading, there was a system interrupt +// + @c RE_FILE_IO: If there was a physical I/O error +// + @c RE_FILE_NOSPACE: If reading failed due to insufficient storage space +i_DECLIMEX_ int32_t rfFgets_UTF16LE(char* buff,uint32_t num,FILE* f,char* eof); +// @brief Gets a number of bytes from a UTF-8 file descriptor +// +// This is a function that's similar to c library fgets but it also returns the number of bytes read. Reads in from the file until @c num characters +// have been read or new line or EOF character has been encountered. +// +// The function automatically adds a null termination character at the end of +// @c buff but this character is not included in the returned actual number of bytes. +// +// The function will read until @c num characters are read and if @c num +// would take us to the middle of a UTF8 character then the next character shall also be read +// and the function will return the number of bytes read. +// Since the function null terminates the buffer the given @c buff needs to be of at least +// @c num+4 size to cater for the worst case. +// +// If right after the last character read comes the EOF, the function +// shall detect so and assign @c true to @c eof. +// +// In Windows where file endings are in the form of 2 bytes CR-LF (Carriage return - NewLine) this function +// shall just ignore the carriage returns and not return it inside the return buffer at @c buff. +// +// The file descriptor at @c f must have been opened in binary and not text mode. That means that if under +// Windows make sure to call fopen with "wb", "rb" e.t.c. instead of the simple "w", "r" e.t.c. since the initial +// default value under Windows is text mode. Alternatively you can set the initial value using _get_fmode() and +// _set_fmode(). For more information take a look at the msdn pages here: +// http://msdn.microsoft.com/en-us/library/ktss1a9b.aspx +// +// @param[in] buff A buffer to be filled with the contents of the file. Should of size at least @c num+4 +// @param[in] num The maximum number of bytes to read from within the file NOT including the null terminating character(which in itelf is 1 byte) +// @param[in] f A valid FILE descriptor from which to read the bytes +// @param[out] eof Pass a reference to a char to receive a true/false value for whether EOF has been reached. +// @return Returns the actual number of bytes read or an error if there was a problem. +// The possible errors are: +// + @c RE_UTF8_INVALID_SEQUENCE_INVALID_BYTE: If an invalid UTF-8 byte has been found +// + @c RE_UTF8_INVALID_SEQUENCE_CONBYTE: If during parsing the file we were expecting a continuation +// byte and did not find it +// + @c RE_UTF8_INVALID_SEQUENCE_END: If the null character is encountered in between bytes that should +// have been continuation bytes +// + @c RE_FILE_READ: If during reading the file there was an unknown read error +// + @c RE_FILE_READ_BLOCK: If the read operation failed due to the file descriptor being occupied by another thread +// + @c RE_FILE_MODE: If during reading the file the file descriptor's mode was not correctly set for reading +// + @c RE_FILE_POS_OVERFLOW: If during reading, the current file position can't be represented by the system +// + @c RE_INTERRUPT: If during reading, there was a system interrupt +// + @c RE_FILE_IO: If there was a physical I/O error +// + @c RE_FILE_NOSPACE: If reading failed due to insufficient storage space +i_DECLIMEX_ int32_t rfFgets_UTF8(char* buff,uint32_t num,FILE* f,char* eof); + +// @brief Gets a unicode character from a UTF-8 file descriptor +// +// This function attempts to assume a more modern fgetc() role for UTF-8 encoded files. +// Reads bytes from the File descriptor @c f until a full UTF-8 unicode character has been read +// +// After this function the file pointer will have moved either by @c 1, @c 2, @c 3 or @c 4 +// bytes if the return value is positive. You can see how much by checking the return value. +// +// You shall need to provide an integer at @c c to contain either the decoded Unicode +// codepoint or the UTF-8 endoced byte depending on the value of the @c cp argument. +// +// @param f A valid FILE descriptor from which to read the bytes +// @param c Pass an int that will receive either the unicode code point value or +// the UTF8 bytes depending on the value of the @c cp flag +// @param cp A boolean flag. If @c true then the int passed at @c c will contain the unicode code point +// of the read character, so the UTF-8 will be decoded. +// If @c false the int passed at @c c will contain the value of the read bytes in UTF-8 without any decoding +// @return Returns the number of bytes read (either @c 1, @c 2, @c 3 or @c 4) or an error if the function +// fails for some reason. Possible error values are: +// + @c RE_FILE_EOF: The end of file has been found while reading. If the end of file is encountered +// in the middle of a UTF-8 encoded character where we would be expecting something different +// and @c RE_UTF8_INVALID_SEQUENCE_END error is also logged +// + @c RE_UTF8_INVALID_SEQUENCE_INVALID_BYTE: If an invalid UTF-8 byte has been found +// + @c RE_UTF8_INVALID_SEQUENCE_CONBYTE: If during parsing the file we were expecting a continuation +// byte and did not find it +// + @c RE_UTF8_INVALID_SEQUENCE_END: If the null character is encountered in between bytes that should +// have been continuation bytes +// + @c RE_FILE_READ: If during reading the file there was an unknown read error +// + @c RE_FILE_READ_BLOCK: If the read operation failed due to the file descriptor being occupied by another thread +// + @c RE_FILE_MODE: If during reading the file the file descriptor's mode was not correctly set for reading +// + @c RE_FILE_POS_OVERFLOW: If during reading, the current file position can't be represented by the system +// + @c RE_INTERRUPT: If during reading, there was a system interrupt +// + @c RE_FILE_IO: If there was a physical I/O error +// + @c RE_FILE_NOSPACE: If reading failed due to insufficient storage space +i_DECLIMEX_ int32_t rfFgetc_UTF8(FILE* f,uint32_t *c,char cp); +// @brief Gets a unicode character from a UTF-16 Big Endian file descriptor +// +// This function attempts to assume a more modern fgetc() role for UTF-16 encoded files. +// Reads bytes from the File descriptor @c f until a full UTF-16 unicode character has been read +// +// After this function the file pointer will have moved either by @c 2 or @c 4 +// bytes if the return value is positive. You can see how much by checking the return value. +// +// You shall need to provide an integer at @c c to contain either the decoded Unicode +// codepoint or the Bigendian encoded UTF-16 bytes depending on the value of @c the cp argument. +// +// @param f A valid FILE descriptor from which to read the bytes +// @param c Pass an int that will receive either the unicode code point value or +// the UTF16 bytes depending on the value of the @c cp flag +// @param cp A boolean flag. If @c true then the int passed at @c c will contain the unicode code point +// of the read character, so the UTF-16 will be decoded. +// If @c false the int passed at @c c will contain the value of the read bytes in UTF-16 without any decoding +// @return Returns the number of bytes read (either @c 2 or @c 4) or an error if the function +// fails for some reason. Possible error values are: +// + @c RE_UTF16_INVALID_SEQUENCE: Either the read word or its surrogate pair if 4 bytes were read held illegal values +// + @c RE_UTF16_NO_SURRPAIR: According to the first read word a surrogate pair was expected but none was found +// + @c RE_FILE_EOF: The end of file has been found while reading. If the end of file is encountered +// while we expect a UTF-16 surrogate pair an appropriate error is logged +// + @c RE_FILE_READ: If during reading the file there was an unknown read error +// + @c RE_FILE_READ_BLOCK: If the read operation failed due to the file descriptor being occupied by another thread +// + @c RE_FILE_MODE: If during reading the file the file descriptor's mode was not correctly set for reading +// + @c RE_FILE_POS_OVERFLOW: If during reading, the current file position can't be represented by the system +// + @c RE_INTERRUPT: If during reading, there was a system interrupt +// + @c RE_FILE_IO: If there was a physical I/O error +// + @c RE_FILE_NOSPACE: If reading failed due to insufficient storage space +i_DECLIMEX_ int32_t rfFgetc_UTF16BE(FILE* f,uint32_t *c,char cp); +// @brief Gets a unicode character from a UTF-16 Little Endian file descriptor +// +// This function attempts to assume a more modern fgetc() role for UTF-16 encoded files. +// Reads bytes from the File descriptor @c f until a full UTF-16 unicode character has been read +// +// After this function the file pointer will have moved either by @c 2 or @c 4 +// bytes if the return value is positive. You can see how much by checking the return value. +// +// You shall need to provide an integer at @c c to contain either the decoded Unicode +// codepoint or the Bigendian encoded UTF-16 bytes depending on the value of @c the cp argument. +// +// @param f A valid FILE descriptor from which to read the bytes +// @param c Pass an int that will receive either the unicode code point value or +// the UTF16 bytes depending on the value of the @c cp flag +// @param cp A boolean flag. If @c true then the int passed at @c c will contain the unicode code point +// of the read character, so the UTF-16 will be decoded. +// If @c false the int passed at @c c will contain the value of the read bytes in UTF-16 without any decoding +// @return Returns the number of bytes read (either @c 2 or @c 4) or an error if the function +// fails for some reason. Possible error values are: +// + @c RE_UTF16_INVALID_SEQUENCE: Either the read word or its surrogate pair if 4 bytes were read held illegal values +// + @c RE_UTF16_NO_SURRPAIR: According to the first read word a surrogate pair was expected but none was found +// + @c RE_FILE_EOF: The end of file has been found while reading. If the end of file is encountered +// while we expect a UTF-16 surrogate pair an appropriate error is logged +// + @c RE_FILE_READ: If during reading the file there was an unknown read error +// + @c RE_FILE_READ_BLOCK: If the read operation failed due to the file descriptor being occupied by another thread +// + @c RE_FILE_MODE: If during reading the file the file descriptor's mode was not correctly set for reading +// + @c RE_FILE_POS_OVERFLOW: If during reading, the current file position can't be represented by the system +// + @c RE_INTERRUPT: If during reading, there was a system interrupt +// + @c RE_FILE_IO: If there was a physical I/O error +// + @c RE_FILE_NOSPACE: If reading failed due to insufficient storage space +i_DECLIMEX_ int32_t rfFgetc_UTF16LE(FILE* f,uint32_t *c,char cp); +// @brief Gets a unicode character from a UTF-32 Little Endian file descriptor +// +// This function attempts to assume a more modern fgetc() role for UTF-32 encoded files. +// Reads bytes from the File descriptor @c f until a full UTF-32 unicode character has been read +// +// After this function the file pointer will have moved by @c 4 +// bytes if the return value is positive. +// +// You shall need to provide an integer at @c to contain the UTF-32 codepoint. +// +// @param f A valid FILE descriptor from which to read the bytes +// @param c Pass an int that will receive either the unicode code point value or +// the UTF16 bytes depending on the value of the @c cp flag +// If @c false the int passed at @c c will contain the value of the read bytes in UTF-16 without any decoding +// @return Returns either @c RF_SUCCESS for succesfull readin or one of the following errors: +// + @c RE_FILE_EOF: The end of file has been found while reading. +// + @c RE_FILE_READ: If during reading the file there was an unknown read error +// + @c RE_FILE_READ_BLOCK: If the read operation failed due to the file descriptor being occupied by another thread +// + @c RE_FILE_MODE: If during reading the file the file descriptor's mode was not correctly set for reading +// + @c RE_FILE_POS_OVERFLOW: If during reading, the current file position can't be represented by the system +// + @c RE_INTERRUPT: If during reading, there was a system interrupt +// + @c RE_FILE_IO: If there was a physical I/O error +// + @c RE_FILE_NOSPACE: If reading failed due to insufficient storage space +i_DECLIMEX_ int32_t rfFgetc_UTF32LE(FILE* f,uint32_t *c); +// @brief Gets a unicode character from a UTF-32 Big Endian file descriptor +// +// This function attempts to assume a more modern fgetc() role for UTF-32 encoded files. +// Reads bytes from the File descriptor @c f until a full UTF-32 unicode character has been read +// +// After this function the file pointer will have moved by @c 4 +// bytes if the return value is positive. +// +// You shall need to provide an integer at @c to contain the UTF-32 codepoint. +// +// @param f A valid FILE descriptor from which to read the bytes +// @param c Pass an int that will receive either the unicode code point value or +// the UTF16 bytes depending on the value of the @c cp flag +// If @c false the int passed at @c c will contain the value of the read bytes in UTF-16 without any decoding +// @return Returns either @c RF_SUCCESS for succesfull readin or one of the following errors: +// + @c RE_FILE_EOF: The end of file has been found while reading. +// + @c RE_FILE_READ: If during reading the file there was an unknown read error +// + @c RE_FILE_READ_BLOCK: If the read operation failed due to the file descriptor being occupied by another thread +// + @c RE_FILE_MODE: If during reading the file the file descriptor's mode was not correctly set for reading +// + @c RE_FILE_POS_OVERFLOW: If during reading, the current file position can't be represented by the system +// + @c RE_INTERRUPT: If during reading, there was a system interrupt +// + @c RE_FILE_IO: If there was a physical I/O error +// + @c RE_FILE_NOSPACE: If reading failed due to insufficient storage space +i_DECLIMEX_ int32_t rfFgetc_UTF32BE(FILE* f,uint32_t *c); + +// @brief Moves a unicode character backwards in a big endian UTF-32 file stream +// +// @param f The file stream +// @param c Returns the character we moved back to as a unicode codepoint +// @return Returns either @c RF_SUCCESS for success or one of the following errors: +// + @c RE_FILE_POS_OVERFLOW: If during trying to read the current file's position it can't be represented by the system +// + @c RE_FILE_BAD: If The file descriptor is corrupt/illegal +// + @c RE_FILE_NOTFILE: If the file descriptor is not a file but something else. e.g. socket. +// + @c RE_FILE_GETFILEPOS: If the file's position could not be retrieved for some unknown reason +// + @c RE_FILE_WRITE_BLOCK: While attempting to move the file pointer, it was occupied by another thread, and the no block flag was set +// + @c RE_INTERRUPT: Operating on the file failed due to a system interrupt +// + @c RE_FILE_IO: There was a physical I/O error +// + @c RE_FILE_NOSPACE: There was no space on the device holding the file +// + @c RE_FILE_NOTFILE: The device we attempted to manipulate is non-existent +// + @c RE_FILE_READ: If during reading the file there was an error +// + @c RE_FILE_READ_BLOCK: If during reading the file the read operation failed due to the file being occupied by another thread +// + @c RE_FILE_MODE: If during reading the file the underlying file descriptor's mode was not correctly set for reading +i_DECLIMEX_ int32_t rfFback_UTF32BE(FILE* f,uint32_t *c); +// @brief Moves a unicode character backwards in a little endian UTF-32 file stream +// +// The file descriptor at @c f must have been opened in binary and not text mode. That means that if under +// Windows make sure to call fopen with "wb", "rb" e.t.c. instead of the simple "w", "r" e.t.c. since the initial +// default value under Windows is text mode. Alternatively you can set the initial value using _get_fmode() and +// _set_fmode(). For more information take a look at the msdn pages here: +// http://msdn.microsoft.com/en-us/library/ktss1a9b.aspx +// +// @param f The file stream +// @param c Returns the character we moved back to as a unicode codepoint +// @return Returns either @c RF_SUCCESS for success or one of the following errors: +// + @c RE_FILE_POS_OVERFLOW: If during trying to read the current file's position it can't be represented by the system +// + @c RE_FILE_BAD: If The file descriptor is corrupt/illegal +// + @c RE_FILE_NOTFILE: If the file descriptor is not a file but something else. e.g. socket. +// + @c RE_FILE_GETFILEPOS: If the file's position could not be retrieved for some unknown reason +// + @c RE_FILE_WRITE_BLOCK: While attempting to move the file pointer, it was occupied by another thread, and the no block flag was set +// + @c RE_INTERRUPT: Operating on the file failed due to a system interrupt +// + @c RE_FILE_IO: There was a physical I/O error +// + @c RE_FILE_NOSPACE: There was no space on the device holding the file +// + @c RE_FILE_NOTFILE: The device we attempted to manipulate is non-existent +// + @c RE_FILE_READ: If during reading the file there was an error +// + @c RE_FILE_READ_BLOCK: If during reading the file the read operation failed due to the file being occupied by another thread +// + @c RE_FILE_MODE: If during reading the file the underlying file descriptor's mode was not correctly set for reading +i_DECLIMEX_ int32_t rfFback_UTF32LE(FILE* f,uint32_t *c); +// @brief Moves a unicode character backwards in a big endian UTF-16 file stream +// +// The file descriptor at @c f must have been opened in binary and not text mode. That means that if under +// Windows make sure to call fopen with "wb", "rb" e.t.c. instead of the simple "w", "r" e.t.c. since the initial +// default value under Windows is text mode. Alternatively you can set the initial value using _get_fmode() and +// _set_fmode(). For more information take a look at the msdn pages here: +// http://msdn.microsoft.com/en-us/library/ktss1a9b.aspx +// +// @param f The file stream +// @param c Returns the character we moved back to as a unicode codepoint +// @return Returns either the number of bytes moved backwards (either @c 4 or @c 2) for success or one of the following errors: +// + @c RE_UTF16_INVALID_SEQUENCE: Either the read word or its surrogate pair if 4 bytes were read held illegal values +// + @c RE_FILE_POS_OVERFLOW: If during trying to read the current file's position it can't be represented by the system +// + @c RE_FILE_BAD: If The file descriptor is corrupt/illegal +// + @c RE_FILE_NOTFILE: If the file descriptor is not a file but something else. e.g. socket. +// + @c RE_FILE_GETFILEPOS: If the file's position could not be retrieved for some unknown reason +// + @c RE_FILE_WRITE_BLOCK: While attempting to move the file pointer, it was occupied by another thread, and the no block flag was set +// + @c RE_INTERRUPT: Operating on the file failed due to a system interrupt +// + @c RE_FILE_IO: There was a physical I/O error +// + @c RE_FILE_NOSPACE: There was no space on the device holding the file +// + @c RE_FILE_NOTFILE: The device we attempted to manipulate is non-existent +// + @c RE_FILE_READ: If during reading the file there was an error +// + @c RE_FILE_READ_BLOCK: If during reading the file the read operation failed due to the file being occupied by another thread +// + @c RE_FILE_MODE: If during reading the file the underlying file descriptor's mode was not correctly set for reading +i_DECLIMEX_ int32_t rfFback_UTF16BE(FILE* f,uint32_t *c); +// @brief Moves a unicode character backwards in a little endian UTF-16 file stream +// +// The file descriptor at @c f must have been opened in binary and not text mode. That means that if under +// Windows make sure to call fopen with "wb", "rb" e.t.c. instead of the simple "w", "r" e.t.c. since the initial +// default value under Windows is text mode. Alternatively you can set the initial value using _get_fmode() and +// _set_fmode(). For more information take a look at the msdn pages here: +// http://msdn.microsoft.com/en-us/library/ktss1a9b.aspx +// +// @param f The file stream +// @param c Returns the character we moved back to as a unicode codepoint +// @return Returns either the number of bytes moved backwards (either @c 4 or @c 2) for success or one of the following errors: +// + @c RE_UTF16_INVALID_SEQUENCE: Either the read word or its surrogate pair if 4 bytes were read held illegal values +// + @c RE_FILE_POS_OVERFLOW: If during trying to read the current file's position it can't be represented by the system +// + @c RE_FILE_BAD: If The file descriptor is corrupt/illegal +// + @c RE_FILE_NOTFILE: If the file descriptor is not a file but something else. e.g. socket. +// + @c RE_FILE_GETFILEPOS: If the file's position could not be retrieved for some unknown reason +// + @c RE_FILE_WRITE_BLOCK: While attempting to move the file pointer, it was occupied by another thread, and the no block flag was set +// + @c RE_INTERRUPT: Operating on the file failed due to a system interrupt +// + @c RE_FILE_IO: There was a physical I/O error +// + @c RE_FILE_NOSPACE: There was no space on the device holding the file +// + @c RE_FILE_NOTFILE: The device we attempted to manipulate is non-existent +// + @c RE_FILE_READ: If during reading the file there was an error +// + @c RE_FILE_READ_BLOCK: If during reading the file the read operation failed due to the file being occupied by another thread +// + @c RE_FILE_MODE: If during reading the file the underlying file descriptor's mode was not correctly set for reading +i_DECLIMEX_ int32_t rfFback_UTF16LE(FILE* f,uint32_t *c); +// @brief Moves a unicode character backwards in a UTF-8 file stream +// +// The file descriptor at @c f must have been opened in binary and not text mode. That means that if under +// Windows make sure to call fopen with "wb", "rb" e.t.c. instead of the simple "w", "r" e.t.c. since the initial +// default value under Windows is text mode. Alternatively you can set the initial value using _get_fmode() and +// _set_fmode(). For more information take a look at the msdn pages here: +// http://msdn.microsoft.com/en-us/library/ktss1a9b.aspx +// +// @param f The file stream +// @param c Returns the character we moved back to as a unicode codepoint +// @return Returns either the number of bytes moved backwards for success (either @c 4, @c 3, @c 2 or @c 1) or one of the following errors: +// + @c RE_UTF8_INVALID_SEQUENCE: If during moving bacwards in the file unexpected UTF-8 bytes were found +// + @c RE_FILE_POS_OVERFLOW: If during trying to read the current file's position it can't be represented by the system +// + @c RE_FILE_BAD: If The file descriptor is corrupt/illegal +// + @c RE_FILE_NOTFILE: If the file descriptor is not a file but something else. e.g. socket. +// + @c RE_FILE_GETFILEPOS: If the file's position could not be retrieved for some unknown reason +// + @c RE_FILE_WRITE_BLOCK: While attempting to move the file pointer, it was occupied by another thread, and the no block flag was set +// + @c RE_INTERRUPT: Operating on the file failed due to a system interrupt +// + @c RE_FILE_IO: There was a physical I/O error +// + @c RE_FILE_NOSPACE: There was no space on the device holding the file +// + @c RE_FILE_NOTFILE: The device we attempted to manipulate is non-existent +// + @c RE_FILE_READ: If during reading the file there was an error +// + @c RE_FILE_READ_BLOCK: If during reading the file the read operation failed due to the file being occupied by another thread +// + @c RE_FILE_MODE: If during reading the file the underlying file descriptor's mode was not correctly set for reading +i_DECLIMEX_ int32_t rfFback_UTF8(FILE* f,uint32_t *c); + +// @brief Opens another process as a pipe +// +// This function is a cross-platform popen wrapper. In linux it uses popen and in Windows it uses +// _popen. +// @lmsFunction +// @param command The string with the command to execute. Is basically the name of the program/process you want to spawn +// with its full path and its parameters. @inhtype{String,StringX} @tmpSTR +// @param mode The mode you want the pipe to work in. There are two possible values: +// + @c "r" The calling process can read the spawned command's standard output via the returned stream. +// + @c "w" The calling process can write to the spawned command's standard input via the returned stream. +// +// Anything else will result in an error +// @return For success popen will return a FILE descriptor that can be used to either read or write from the pipe. +// If there was an error @c 0 is returned and an error is logged. +#ifdef RF_IAMHERE_FOR_DOXYGEN +i_DECLIMEX_ FILE* rfPopen(void* command,const char* mode); +#else +i_DECLIMEX_ FILE* i_rfPopen(void* command,const char* mode); +#define rfPopen(i_CMD_,i_MODE_) i_rfLMS_WRAP2(FILE*,i_rfPopen,i_CMD_,i_MODE_) +#endif + +// @brief Closes a pipe +// +// This function is a cross-platform wrapper for pclose. It closes a file descriptor opened with @ref rfPopen() and +// returns the exit code of the process that was running +// @param stream The file descriptor of the pipe returned by @ref rfPopen() that we want to close +// @return Returns the exit code of the process or -1 if there was an error +i_DECLIMEX_ int rfPclose(FILE* stream); + +// @} End of I/O group + +#ifdef __cplusplus +}///closing bracket for calling from C++ +#endif + + +#endif//include guards end diff --git a/samples/C/rfc_string.c b/samples/C/rfc_string.c new file mode 100644 index 00000000..3b98a7a4 --- /dev/null +++ b/samples/C/rfc_string.c @@ -0,0 +1,2348 @@ +/** +** Copyright (c) 2011-2012, Karapetsas Eleftherios +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: +** 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the distribution. +** 3. Neither the name of the Original Author of Refu nor the names of its contributors may be used to endorse or promote products derived from +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, +** INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +** SERVICES;LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**/ +#include + +#include +// include bitwise operations +#include +// include the private functions and macros +#include "string_private.h" +// include io_private only for the write check +#include "../IO/io_private.h" +// include the extended strin +#include +// for HUGE_VAL definition +#include + +#include // for the local stack memory + +/*********************************************************************** Start of the RF_String functions *****************************************************************************************/ + +/*-------------------------------------------------------------------------Methods to create an RF_String-------------------------------------------------------------------------------*/ + +// Allocates and returns a string with the given characters a refu string with the given characters. Given characters have to be in UTF-8. A check for valide sequence of bytes is performed. +#ifndef RF_OPTION_DEFAULT_ARGUMENTS +RF_String* rfString_Create(const char* s,...) +#else +RF_String* i_rfString_Create(const char* s,...) +#endif +{ + READ_VSNPRINTF_ARGS(s,s,0) + + // check for validity of the given sequence and get the character length + uint32_t byteLength; + if( rfUTF8_VerifySequence(buff,&byteLength) == RF_FAILURE) + { + LOG_ERROR("Error at String Allocation due to invalid UTF-8 byte sequence",RE_STRING_INIT_FAILURE); + if(buffAllocated == true) + free(buff); + return 0; + } + + RF_String* ret; + RF_MALLOC(ret,sizeof(RF_String)); + // get length + ret->byteLength = byteLength; + + // now that we know the length we can allocate the buffer and copy the bytes + RF_MALLOC(ret->bytes,ret->byteLength+1); + memcpy(ret->bytes,buff,ret->byteLength+1); + if(buffAllocated==true) + free(buff); + return ret; +} +#ifdef RF_OPTION_DEFAULT_ARGUMENTS +RF_String* i_NVrfString_Create(const char* s) +{ + // check for validity of the given sequence and get the character length + uint32_t byteLength; + if( rfUTF8_VerifySequence(s,&byteLength) == RF_FAILURE) + { + LOG_ERROR("Error at String Allocation due to invalid UTF-8 byte sequence",RE_STRING_INIT_FAILURE); + return 0; + } + + RF_String* ret; + RF_MALLOC(ret,sizeof(RF_String)); + // get length + ret->byteLength = byteLength; + + // now that we know the length we can allocate the buffer and copy the bytes + RF_MALLOC(ret->bytes,ret->byteLength+1); + memcpy(ret->bytes,s,ret->byteLength+1); + + return ret; +} +#endif + + +// Allocates and returns a string with the given characters a refu string with the given characters. Given characters have to be in UTF-8. A check for valid sequence of bytes is performed. +RF_String* i_rfString_CreateLocal1(const char* s,...) +{ +#if RF_OPTION_SOURCE_ENCODING != RF_UTF8 + uint32_t characterLength,*codepoints,i=0,j; +#endif + // remember the stack pointer before this macro evaluation + rfLMS_MacroEvalPtr(RF_LMS); + // read the var args + READ_VSNPRINTF_ARGS(s,s,0) +// /===Start of Non-UTF-8 code===// / +#if (RF_OPTION_SOURCE_ENCODING == RF_UTF16_LE) || (RF_OPTION_SOURCE_ENCODING == RF_UTF16_BE) + // find the bytelength of the UTF-16 buffer + while(buff[i] != '\0' && buff[i+1]!= '\0') + i++; + i+=2; + // allocate the codepoint buffer + RF_MALLOC(codepoints,i/2) +#elif (RF_OPTION_SOURCE_ENCODING == RF_UTF32_LE) || (RF_OPTION_SOURCE_ENCODING == RF_UTF32_BE) + // find the bytelength of the UTF-32 buffer + while(buff[i] != '\0' && buff[i+1]!= '\0' && buff[i+2]!= '\0' && buff[i+3]!= '\0') + i++; + i+=4; + // allocate the codepoint buffer + RF_MALLOC(codepoints,i) +#endif +#if (RF_OPTION_SOURCE_ENCODING == RF_UTF16_LE)// decode the UTF16 + if(rfUTILS_Endianess() == RF_LITTLE_ENDIAN) + if(rfUTF16_Decode(buff,&characterLength,codepoints) == false) + goto cleanup; + else + if(rfUTF16_Decode_swap(buff,&characterLength,codepoints)==false) + goto cleanup; + +#elif RF_OPTION_SOURCE_ENCODING == RF_UTF16_BE// decode the UTF16 + if(rfUTILS_Endianess() == RF_LITTLE_ENDIAN) + if(rfUTF16_Decode_swap(buff,&characterLength,codepoints) == false) + goto cleanup; + else + if(rfUTF16_Decode(buff,&characterLength,codepoints)==false) + goto cleanup; +#elif RF_OPTION_SOURCE_ENCODING == RF_UTF32_LE// copy the UTF32 into the codepoint + memcpy(codepoints,buff,i); + if(rfUTILS_Endianess != RF_LITTLE_ENDIAN) + { + for(j=0;jbyteLength = byteLength; + + // now that we know the length we can allocate the buffer and copy the bytes + ret->bytes = rfLMS_Push(RF_LMS,ret->byteLength+1); + if(ret->bytes == 0) + { + LOG_ERROR("Memory allocation from the Local Memory Stack failed. Insufficient local memory stack space. Consider compiling the library with bigger stack space. Quitting proccess...", + RE_LOCALMEMSTACK_INSUFFICIENT); + exit(RE_LOCALMEMSTACK_INSUFFICIENT); + } + memcpy(ret->bytes,buff,ret->byteLength+1); + // finally free stuff if needed + if(buffAllocated == true) + free(buff); + return ret; + +// /cleanup code for non-UTF-8 cases +#if (RF_OPTION_SOURCE_ENCODING == RF_UTF16_LE) || (RF_OPTION_SOURCE_ENCODING == RF_UTF16_BE) +cleanup: +#if RF_OPTION_SOURCE_ENCODING == RF_UTF16_LE + LOG_ERROR("Temporary RF_String creation from a UTF-16 Little Endian buffer failed due to UTF-16 decoding failure",RE_UTF16_INVALID_SEQUENCE); +#elif RF_OPTION_SOURCE_ENCODING == RF_UTF16_BE + LOG_ERROR("Temporary RF_String creation from a UTF-16 Big Endian buffer failed due to UTF-16 decoding failure",RE_UTF16_INVALID_SEQUENCE); +#endif + free(codepoints); + if(buffAllocated == true) + free(buff); + return 0; +#endif +} +RF_String* i_NVrfString_CreateLocal(const char* s) +{ +#if RF_OPTION_SOURCE_ENCODING != RF_UTF8 + uint32_t characterLength,*codepoints,i=0,j; + char* buff; +#endif + // remember the stack pointer before this macro evaluation + rfLMS_MacroEvalPtr(RF_LMS); +// /===Start of Non-UTF-8 code===// / +#if (RF_OPTION_SOURCE_ENCODING == RF_UTF16_LE) || (RF_OPTION_SOURCE_ENCODING == RF_UTF16_BE) + // find the bytelength of the UTF-16 buffer + while(s[i] != '\0' &&s[i+1]!= '\0') + i++; + i+=2; + // allocate the codepoint buffer + RF_MALLOC(codepoints,i/2) +#elif (RF_OPTION_SOURCE_ENCODING == RF_UTF32_LE) || (RF_OPTION_SOURCE_ENCODING == RF_UTF32_BE) + // find the bytelength of the UTF-32 buffer + while(s[i] != '\0' && s[i+1]!= '\0' && s[i+2]!= '\0' && s[i+3]!= '\0') + i++; + i+=4; + // allocate the codepoint buffer + RF_MALLOC(codepoints,i) +#endif +#if (RF_OPTION_SOURCE_ENCODING == RF_UTF16_LE)// decode the UTF16 + if(rfUTILS_Endianess() == RF_LITTLE_ENDIAN) + if(rfUTF16_Decode(s,&characterLength,codepoints) == false) + goto cleanup; + else + if(rfUTF16_Decode_swap(s,&characterLength,codepoints)==false) + goto cleanup; + +#elif RF_OPTION_SOURCE_ENCODING == RF_UTF16_BE// decode the UTF16 + if(rfUTILS_Endianess() == RF_LITTLE_ENDIAN) + if(rfUTF16_Decode_swap(s,&characterLength,codepoints) == false) + goto cleanup; + else + if(rfUTF16_Decode(s,&characterLength,codepoints)==false) + goto cleanup; +#elif RF_OPTION_SOURCE_ENCODING == RF_UTF32_LE// copy the UTF32 into the codepoint + memcpy(codepoints,s,i); + if(rfUTILS_Endianess != RF_LITTLE_ENDIAN) + { + for(j=0;jbyteLength = byteLength; + + ret->bytes = rfLMS_Push(RF_LMS,ret->byteLength+1); + if(ret->bytes == 0) + { + LOG_ERROR("Memory allocation from the Local Memory Stack failed during string allocation. Insufficient local memory stack space. Consider compiling the library with bigger stack space. Quitting proccess...", + RE_LOCALMEMSTACK_INSUFFICIENT); + exit(RE_LOCALMEMSTACK_INSUFFICIENT); + } +#if RF_OPTION_SOURCE_ENCODING == RF_UTF8 + memcpy(ret->bytes,s,ret->byteLength+1); +#else + memcpy(ret->bytes,buff,ret->byteLength+1); +#endif + return ret; + +// /cleanup code for non-UTF-8 cases +#if (RF_OPTION_SOURCE_ENCODING == RF_UTF16_LE) || (RF_OPTION_SOURCE_ENCODING == RF_UTF16_BE) +cleanup: +#if RF_OPTION_SOURCE_ENCODING == RF_UTF16_LE + LOG_ERROR("Temporary RF_String creation from a UTF-16 Little Endian buffer failed due to UTF-16 decoding failure",RE_UTF16_INVALID_SEQUENCE); +#elif RF_OPTION_SOURCE_ENCODING == RF_UTF16_BE + LOG_ERROR("Temporary RF_String creation from a UTF-16 Big Endian buffer failed due to UTF-16 decoding failure",RE_UTF16_INVALID_SEQUENCE); +#endif + free(codepoints); + return 0; +#endif +} + + + +// Initializes a string with the given characters. Given characters have to be in UTF-8. A check for valide sequence of bytes is performed.Can't be used with RF_StringX +#ifndef RF_OPTION_DEFAULT_ARGUMENTS +char rfString_Init(RF_String* str,const char* s,...) +#else +char i_rfString_Init(RF_String* str,const char* s,...) +#endif +{ + READ_VSNPRINTF_ARGS(s,s,false) + // check for validity of the given sequence and get the character length + uint32_t byteLength; + if( rfUTF8_VerifySequence(buff,&byteLength) == RF_FAILURE) + { + LOG_ERROR("Error at String Initialization due to invalid UTF-8 byte sequence",RE_STRING_INIT_FAILURE); + if(buffAllocated==true) + free(buff); + return false; + } + + // get length + str->byteLength = byteLength; + + // now that we know the length we can allocate the buffer and copy the bytes + RF_MALLOC(str->bytes,str->byteLength+1); + memcpy(str->bytes,buff,str->byteLength+1); + if(buffAllocated == true) + free(buff); + return true; +} +#ifdef RF_OPTION_DEFAULT_ARGUMENTS +char i_NVrfString_Init(RF_String* str,const char* s) +{ + // check for validity of the given sequence and get the character length + uint32_t byteLength; + if( rfUTF8_VerifySequence(s,&byteLength) == RF_FAILURE) + { + LOG_ERROR("Error at String Initialization due to invalid UTF-8 byte sequence",RE_STRING_INIT_FAILURE); + return false; + } + + // get length + str->byteLength = byteLength; + + // now that we know the length we can allocate the buffer and copy the bytes + RF_MALLOC(str->bytes,str->byteLength+1); + memcpy(str->bytes,s,str->byteLength+1); + + return true; +} +#endif + +// Allocates a String by turning a unicode code point in a String (encoded in UTF-8). +RF_String* rfString_Create_cp(uint32_t codepoint) +{ + RF_String* ret; + RF_MALLOC(ret,sizeof(RF_String)); + if(rfString_Init_cp(ret,codepoint) == true) + { + return ret; + } + // failure + free(ret); + return 0; +} + +// Initializes a string by turning a unicode code point in a String (encoded in UTF-8). +char rfString_Init_cp(RF_String* str, uint32_t codepoint) +{ + // alloc enough for a character + RF_MALLOC(str->bytes,5) + + // if we only need a byte to encode it + if(RF_HEXLE_UI(codepoint,0x007f)) + { + str->bytes[0] = codepoint; + str->bytes[1] = '\0'; + str->byteLength = 1; + } + // if we need 2 bytes to encode it + else if( RF_HEXGE_UI(codepoint,0x0080) && RF_HEXLE_UI(codepoint,0x07ff)) + { + // get the first bits of the first byte and encode them to the first byte + str->bytes[1] = (codepoint & 0x3F)|(0x02<<6); + // get the 5 following bits and encode them in the second byte + str->bytes[0] = ((codepoint & 0x7C0) >> 6) | (0x6<<5); + str->bytes[2] = '\0'; + str->byteLength = 2; + } + // if we need 3 bytes to encode it + else if( RF_HEXGE_UI(codepoint,0x0800) && RF_HEXLE_UI(codepoint,0x0ffff)) + { + // get the first bits of the first byte and encode them to the first byte + str->bytes[2] = (codepoint & 0x3F)|(0x02<<6); + // get the 6 following bits and encode them in the second byte + str->bytes[1] = ((codepoint & 0xFC0) >> 6) | (0x02<<6); + // get the 4 following bits and encode them in the third byte + str->bytes[0] = (((codepoint & 0xF000))>>12) | (0xE<<4); + str->bytes[3] = '\0'; + str->byteLength = 3; + } + // if we need 4 bytes to encode it + else if( RF_HEXGE_UI(codepoint,0x10000) && RF_HEXLE_UI(codepoint,0x10ffff)) + { + // get the first bits of the first byte and encode them to the first byte + str->bytes[3] = (codepoint & 0x3F)|(0x02<<6); + // get the 6 following bits and encode them in the second byte + str->bytes[2] = ((codepoint & 0xFC0) >> 6) | (0x02<<6); + // get the 6 following bits and encode them in the third byte + str->bytes[1] = (((codepoint & 0x3F000))>>12) | (0x02<<6); + // get the 3 following bits and encode them in the fourth byte + str->bytes[0] = (((codepoint & 0x1C0000))>>18) | (0x1E<<3); + str->bytes[4] = '\0'; + str->byteLength = 4; + } + else + { + LOG_ERROR("Attempted to encode an invalid unicode code point into a string",RE_UTF8_INVALID_CODE_POINT); + free(str->bytes); + return false; + } + + return true; +} + + +// Allocates and returns a string with the given integer +RF_String* rfString_Create_i(int32_t i) +{ + // the size of the int32_t buffer + int32_t numLen; + // put the int32_t into a buffer and turn it in a char* + char buff[12];// max uint32_t is 4,294,967,295 in most environment so 12 chars will certainly fit it + sprintf(buff,"%d",i); + numLen = strlen(buff); + + // initialize the string and return it + RF_String* ret; + RF_MALLOC(ret,sizeof(RF_String)); + ret->byteLength = numLen; + RF_MALLOC(ret->bytes,numLen+1); + strcpy(ret->bytes,buff); + return ret; +} +// Initializes a string with the given integer. +char rfString_Init_i(RF_String* str, int32_t i) +{ + // the size of the int32_t buffer + int32_t numLen; + // put the int32_t into a buffer and turn it in a char* + char buff[12];// max uint32_t is 4,294,967,295 in most environment so 12 chars will certainly fit it + sprintf(buff,"%d",i); + numLen = strlen(buff); + + + str->byteLength = numLen; + RF_MALLOC(str->bytes,numLen+1); + strcpy(str->bytes,buff); + + return true; +} + +// Allocates and returns a string with the given float +RF_String* rfString_Create_f(float f) +{ + // allocate a buffer for the float in characters + char* buff; + RF_MALLOC(buff,128); + sprintf(buff,"%f",f); + uint32_t len = strlen(buff); + + // initialize and return the string + RF_String* ret; + RF_MALLOC(ret,sizeof(RF_String)); + ret->byteLength = len; + RF_MALLOC(ret->bytes,len+1); + strcpy(ret->bytes,buff); + + free(buff); + + return ret; +} +// Initializes a string with the given float +char rfString_Init_f(RF_String* str,float f) +{ + // allocate a buffer for the float in characters + char* buff; + RF_MALLOC(buff,128); + sprintf(buff,"%f",f); + uint32_t len = strlen(buff); + + + str->byteLength = len; + RF_MALLOC(str->bytes,len+1); + strcpy(str->bytes,buff); + free(buff); + + // success + return true; +} + +// Allocates and returns a string with the given UTF-16 byte sequence. Given characters have to be in UTF-16. A check for valid sequence of bytes is performed.Can't be used with RF_StringX +RF_String* rfString_Create_UTF16(const char* s,char endianess) +{ + RF_String* ret; + RF_MALLOC(ret,sizeof(RF_String)); + if(rfString_Init_UTF16(ret,s,endianess)==false) + { + free(ret); + return 0; + } + return ret; +} +// Initializes a string with the given UTF-16 byte sequence. Given characters have to be in UTF-16. A check for valid sequence of bytes is performed.Can't be used with RF_StringX +char rfString_Init_UTF16(RF_String* str,const char* s,char endianess) +{ + // decode the utf-16 and get the code points + uint32_t* codepoints; + uint32_t byteLength,characterLength,utf8ByteLength; + char* utf8; + byteLength = 0; + while(s[byteLength]!= 0 || s[byteLength+1]!=0) + { + byteLength++; + } + byteLength+=3;// for the last utf-16 null termination character + RF_MALLOC(codepoints,byteLength*2) // allocate the codepoints + // parse the given byte stream depending on the endianess parameter + switch(endianess) + { + case RF_LITTLE_ENDIAN: + case RF_BIG_ENDIAN: + if(rfUTILS_Endianess() == endianess)// same endianess as the local + { + if(rfUTF16_Decode(s,&characterLength,codepoints) == false) + { + free(codepoints); + LOG_ERROR("String initialization failed due to invalide UTF-16 sequence",RE_STRING_INIT_FAILURE); + return false; + } + } + else// different + { + if(rfUTF16_Decode_swap(s,&characterLength,codepoints) == false) + { + free(codepoints); + LOG_ERROR("String initialization failed due to invalide UTF-16 sequence",RE_STRING_INIT_FAILURE); + return false; + } + } + break; + default: + LOG_ERROR("Illegal endianess value provided",RE_INPUT); + free(codepoints); + return false; + break; + }// switch ends + // now encode these codepoints into UTF8 + if( (utf8 = rfUTF8_Encode(codepoints,characterLength,&utf8ByteLength))==0) + { + free(codepoints); + return false; + } + // success + free(codepoints); + str->bytes = utf8; + str->byteLength = utf8ByteLength; + return true; + +} + +// Allocates and returns a string with the given UTF-32 byte sequence. Given characters have to be in UTF-32. +RF_String* rfString_Create_UTF32(const char* s) +{ + RF_String* ret; + RF_MALLOC(ret,sizeof(RF_String)); + if(rfString_Init_UTF32(ret,s)==false) + { + free(ret); + return 0; + } + return ret; +} +// Initializes a string with the given UTF-32 byte sequence. Given characters have to be in UTF-32. +char rfString_Init_UTF32(RF_String* str,const char* s) +{ + char swapE = false; + uint32_t off = 0; + int32_t i = 0; + + // get the buffer and if swapping is needed do it for all character + uint32_t* codeBuffer = (uint32_t*)(s+off); + + // first of all check for existence of BOM in the beginning of the sequence + if(RF_HEXEQ_UI(codeBuffer[0],0xFEFF))// big endian + { + if(rfUTILS_Endianess()==RF_LITTLE_ENDIAN) + swapE = true; + } + if(RF_HEXEQ_UI(codeBuffer[0],0xFFFE0000))// little + { + if(rfUTILS_Endianess()==RF_BIG_ENDIAN) + swapE = true; + } + else// according to the standard no BOM means big endian + { + if(rfUTILS_Endianess() == RF_LITTLE_ENDIAN) + swapE = true; + } + + // if we need to have endianess swapped do it + if(swapE==true) + { + while(codeBuffer[i] != 0) + { + rfUTILS_SwapEndianUI(codeBuffer+i); + i++; + } + } + // find the length of the utf32 buffer in characters + uint32_t length; + rfUTF32_Length(codeBuffer,length); + + // turn the codepoints into a utf-8 encoded buffer + char* utf8;uint32_t utf8ByteLength; + if((utf8=rfUTF8_Encode(codeBuffer,length,&utf8ByteLength)) == 0) + { + return false;// error + } + // if the encoding happened correctly + if(codeBuffer != 0) + { + str->bytes = (char*)codeBuffer; + str->byteLength = utf8ByteLength; + return true; + } + // else return failure + return false; +} + +// Assigns the value of the source string to the destination.Both strings should already be initialized and hold a value. It is an error to give null parameters. +void i_rfString_Assign(RF_String* dest,void* sourceP) +{ + RF_String* source = (RF_String*)sourceP; + // only if the new string value won't fit in the buffer reallocate the buffer (let's avoid unecessary reallocs) + if(source->byteLength > dest->byteLength) + { + RF_REALLOC(dest->bytes,char,source->byteLength+1); + } + // now copy the value + memcpy(dest->bytes,source->bytes,source->byteLength+1); + // and fix the lengths + dest->byteLength = source->byteLength; +} + +// Assigns the value of a unicode character to the string +char rfString_Assign_char(RF_String* str,uint32_t codepoint) +{ + // realloc if needed + if(str->byteLength <5) + { + RF_REALLOC(str->bytes,char,5); + } + // if we only need a byte to encode it + if(RF_HEXLE_UI(codepoint,0x007f)) + { + str->bytes[0] = codepoint; + str->bytes[1] = '\0'; + str->byteLength = 1; + } + // if we need 2 bytes to encode it + else if( RF_HEXGE_UI(codepoint,0x0080) && RF_HEXLE_UI(codepoint,0x07ff)) + { + // get the first bits of the first byte and encode them to the first byte + str->bytes[1] = (codepoint & 0x3F)|(0x02<<6); + // get the 5 following bits and encode them in the second byte + str->bytes[0] = ((codepoint & 0x7C0) >> 6) | (0x6<<5); + str->bytes[2] = '\0'; + str->byteLength = 2; + } + // if we need 3 bytes to encode it + else if( RF_HEXGE_UI(codepoint,0x0800) && RF_HEXLE_UI(codepoint,0x0ffff)) + { + // get the first bits of the first byte and encode them to the first byte + str->bytes[2] = (codepoint & 0x3F)|(0x02<<6); + // get the 6 following bits and encode them in the second byte + str->bytes[1] = ((codepoint & 0xFC0) >> 6) | (0x02<<6); + // get the 4 following bits and encode them in the third byte + str->bytes[0] = (((codepoint & 0xF000))>>12) | (0xE<<4); + str->bytes[3] = '\0'; + str->byteLength = 3; + } + // if we need 4 bytes to encode it + else if( RF_HEXGE_UI(codepoint,0x10000) && RF_HEXLE_UI(codepoint,0x10ffff)) + { + // get the first bits of the first byte and encode them to the first byte + str->bytes[3] = (codepoint & 0x3F)|(0x02<<6); + // get the 6 following bits and encode them in the second byte + str->bytes[2] = ((codepoint & 0xFC0) >> 6) | (0x02<<6); + // get the 6 following bits and encode them in the third byte + str->bytes[1] = (((codepoint & 0x3F000))>>12) | (0x02<<6); + // get the 3 following bits and encode them in the fourth byte + str->bytes[0] = (((codepoint & 0x1C0000))>>18) | (0x1E<<3); + str->bytes[4] = '\0'; + str->byteLength = 4; + } + else + { + LOG_ERROR("Attempted to encode an invalid unicode code point into a string",RE_UTF8_INVALID_CODE_POINT); + return false; + } + + return true; +} + +// Allocates and returns a string with the given characters. NO VALID-UTF8 check is performed +#ifndef RF_OPTION_DEFAULT_ARGUMENTS +RF_String* rfString_Create_nc(const char* s,...) +#else +RF_String* i_rfString_Create_nc(const char* s,...) +#endif +{ + RF_String* ret; + RF_MALLOC(ret,sizeof(RF_String)); + // get the formatted string + READ_VSNPRINTF_ARGS(s,s,0); + // get the lengt of the byte buffer + ret->byteLength = bytesWritten; + + // now that we know the length we can allocate the buffer and copy the bytes + RF_MALLOC(ret->bytes,ret->byteLength+1); + memcpy(ret->bytes,buff,ret->byteLength+1); + if(buffAllocated) + free(buff); + return ret; +} +#ifdef RF_OPTION_DEFAULT_ARGUMENTS +RF_String* i_NVrfString_Create_nc(const char* s) +{ + RF_String* ret; + RF_MALLOC(ret,sizeof(RF_String)); + // get length + ret->byteLength = strlen(s); + + // now that we know the length we can allocate the buffer and copy the bytes + RF_MALLOC(ret->bytes,ret->byteLength+1); + memcpy(ret->bytes,s,ret->byteLength+1); + return ret; +} +#endif + +// Initializes a string with the given characters. NO VALID-UTF8 check is performed +#ifndef RF_OPTION_DEFAULT_ARGUMENTS +char rfString_Init_nc(struct RF_String* str,const char* s,...) +#else +char i_rfString_Init_nc(struct RF_String* str,const char* s,...) +#endif +{ + // get the formatted string + READ_VSNPRINTF_ARGS(s,s,false) + // get its length + str->byteLength = bytesWritten; + + // now that we know the length we can allocate the buffer and copy the bytes + RF_MALLOC(str->bytes,str->byteLength+1); + memcpy(str->bytes,buff,str->byteLength+1); + if(buffAllocated == true) + free(buff); + return true; +} +#ifdef RF_OPTION_DEFAULT_ARGUMENTS +char i_NVrfString_Init_nc(struct RF_String* str,const char* s) +{ + // get its length + str->byteLength = strlen(s); + + // now that we know the length we can allocate the buffer and copy the bytes + RF_MALLOC(str->bytes,str->byteLength+1); + memcpy(str->bytes,s,str->byteLength+1); + return true; +} +#endif + +/*-------------------------------------------------------------------------Methods to get rid of an RF_String-------------------------------------------------------------------------------*/ + +// Deletes a string object and also frees its pointer.It is an error to give a NULL(0x0) string for deleting. Will most probably lead to a segmentation fault +void rfString_Destroy(RF_String* s) +{ + free(s->bytes); + free(s); +} +// Deletes a string object only, not its memory.It is an error to give a NULL(0x0) string for deleting. Will most probably lead to a segmentation fault +void rfString_Deinit(RF_String* s) +{ + free(s->bytes); +} +/*------------------------------------------------------------------------ RF_String unicode conversio functions-------------------------------------------------------------------------------*/ + +// Returns the strings contents as a UTF-16 buffer +uint16_t* rfString_ToUTF16(RF_String* s,uint32_t* length) +{ + uint32_t* codepoints,charsN; + // get the unicode codepoints, no check here since RF_String is always guaranteed to have valid UTF=8 and as such valid codepoints + codepoints = rfUTF8_Decode(s->bytes,s->byteLength,&charsN); + // encode them in UTF-16, no check here since it comes from an RF_String which is always guaranteed to have valid UTF-8 and as such valid codepoints + return rfUTF16_Encode(codepoints,charsN,length); +} + +// Returns the strings contents as a UTF-32 buffer +uint32_t* rfString_ToUTF32(RF_String* s,uint32_t* length) +{ + // get the unicode codepoints, no check here since RF_String is always guaranteed to have valid UTF=8 and as such valid codepoints + return rfUTF8_Decode(s->bytes,s->byteLength,length); +} + +/*------------------------------------------------------------------------ RF_String retrieval functions-------------------------------------------------------------------------------*/ +// Finds the length of the string in characters +uint32_t rfString_Length(void* str) +{ + RF_String* s = (RF_String*)str; + uint32_t length,i; + RF_STRING_ITERATE_START(s,length,i) + RF_STRING_ITERATE_END(length,i); + return length; +} + +// Retrieves the unicode code point of the parameter character. +uint32_t rfString_GetChar(void* str,uint32_t c) +{ + RF_String* thisstr = (RF_String*)str; + uint32_t length,i; + uint32_t codePoint = RF_STRING_INDEX_OUT_OF_BOUNDS; + RF_STRING_ITERATE_START(thisstr,length,i) + // if we found the character,inspect the 4 different cases + if(length == c) + { + // take the codepoint from the byte position and break from the loop + codePoint = rfString_BytePosToCodePoint(thisstr,i); + break; + } + RF_STRING_ITERATE_END(length,i) + + // and return the code point. Notice that if the character was not found this will return RF_STRING_INDEX_OUT_OF_BOUNDS + return codePoint; +} + +// Retrieves the unicode code point of the parameter bytepos of the string. If the byte position is not the start of a character 0 is returned. This is an internal function, there is no need to use it. Can be used with StringX +uint32_t rfString_BytePosToCodePoint(void* str,uint32_t i) +{ + uint32_t codePoint=0; + RF_String* thisstr = (RF_String*)str; + // /Here I am not checking if byte position 'i' is withing bounds and especially if it is a start of a character + // / This is assumed to have been checked or to be known beforehand by the programmer. That's one of the reasons + // / why this is an internal function and should not be used unless you know what you are doing + // if the lead bit of the byte is 0 then range is : U+0000 to U+0007F (1 byte) + if( ((thisstr->bytes[i] & 0x80)>>7) == 0 ) + { + // and the code point is this whole byte only + codePoint = thisstr->bytes[i]; + } + // if the leading bits are in the form of 0b110xxxxx then range is: U+0080 to U+07FF (2 bytes) + else if ( RF_HEXEQ_C( ( (~(thisstr->bytes[i] ^ 0xC0))>>5),0x7) ) + { + codePoint =0; + // from the second byte take the first 6 bits + codePoint = (thisstr->bytes[i+1] & 0x3F) ; + // from the first byte take the first 5 bits and put them in the start + codePoint |= ((thisstr->bytes[i] & 0x1F) << 6); + } + // if the leading bits are in the form of 0b1110xxxx then range is U+0800 to U+FFFF (3 bytes) + else if( RF_HEXEQ_C( ( (~(thisstr->bytes[i] ^ 0xE0))>>4),0xF) ) + { + codePoint = 0; + // from the third byte take the first 6 bits + codePoint = (thisstr->bytes[i+2] & 0x3F) ; + // from the second byte take the first 6 bits and put them to the left of the previous 6 bits + codePoint |= ((thisstr->bytes[i+1] & 0x3F) << 6); + // from the first byte take the first 4 bits and put them to the left of the previous 6 bits + codePoint |= ((thisstr->bytes[i] & 0xF) << 12); + } + // if the leading bits are in the form of 0b11110xxx then range is U+010000 to U+10FFFF (4 bytes) + else if( RF_HEXEQ_C( ( (~(thisstr->bytes[i] ^ 0xF0))>>3), 0x1F)) + { + codePoint = 0; + // from the fourth byte take the first 6 bits + codePoint = (thisstr->bytes[i+3] & 0x3F) ; + // from the third byte take the first 6 bits and put them to the left of the previous 6 bits + codePoint |= ((thisstr->bytes[i+2] & 0x3F) << 6); + // from the second byte take the first 6 bits and put them to the left of the previous 6 bits + codePoint |= ((thisstr->bytes[i+1] & 0x3F) << 12); + // from the first byte take the first 3 bits and put them to the left of the previous 6 bits + codePoint |= ((thisstr->bytes[i] & 0x7) << 18); + } + + return codePoint; +} + + +// Retrieves character position of a byte position +uint32_t rfString_BytePosToCharPos(void* thisstrP,uint32_t bytepos,char before) +{ + // /here there is no check if this is actually a byte pos inside the string's + // /byte buffer. The programmer should have made sure it is before hand. This is why it is + // / an internal function and should only be used if you know what you are doing + RF_String* thisstr = (RF_String*)thisstrP; + uint32_t charPos = 0; + uint32_t byteI = 0; + // iterate the string's bytes until you get to the required byte + // if it is not a continuation byte, return the position + if(rfUTF8_IsContinuationByte(thisstr->bytes[bytepos])==false) + { + RF_STRING_ITERATE_START(thisstr,charPos,byteI) + if(byteI == bytepos) + return charPos; + RF_STRING_ITERATE_END(charPos,byteI) + } + // else iterate the string's bytes until you get anything bigger than the required byte + RF_STRING_ITERATE_START(thisstr,charPos,byteI) + if(byteI > bytepos) + break; + RF_STRING_ITERATE_END(charPos,byteI) + // if we need the previous one return it + if(before == true) + return charPos-1; + // else return this + return charPos; +} + +// Compares two Strings and returns true if they are equal and false otherwise +char i_rfString_Equal(void* s1P,void* s2P) +{ + RF_String* s1 = (RF_String*)s1P; + RF_String* s2 = (RF_String*)s2P; + if( strcmp(s1->bytes,s2->bytes)==0) + { + return true; + } + return false; +} + +// Finds the existence of String sstr inside this string, either matching case or not +int32_t i_rfString_Find(const void* str,const void* sstrP,const char* optionsP) +{ + // / @note TO SELF: If I make any changes to this function do not forget to change the private version that returns byte position too + // / located at string_private.c and called rfString_FindByte and rfString_FindByte_s + RF_String* thisstr = (RF_String*)str; + RF_String* sstr = (RF_String*)sstrP; + char options = *optionsP; + + char* found = 0; + // if we want to match the case of the string then it's a simple search of matching characters + if( (RF_BITFLAG_ON( options,RF_CASE_IGNORE)) == false) + { + // if it is not found + if( (found = strstr(thisstr->bytes,sstr->bytes)) == 0) + { + return RF_FAILURE; + } + // get the byte position + uint32_t bytepos = found-thisstr->bytes; + // if we need the exact string as it is given + if(RF_BITFLAG_ON( options,RF_MATCH_WORD)) + { + // check before the found string + if(bytepos != 0) + { + // if is is not a character + switch(thisstr->bytes[bytepos-1]) + { + case ' ':case '\t':case '\n': + break; + default: + return RF_FAILURE; + break; + } + } + // check after the found string + if(bytepos+sstr->byteLength != thisstr->byteLength) + { + // if is is not a character + switch(thisstr->bytes[bytepos+sstr->byteLength]) + { + case ' ':case '\t':case '\n': + break; + default: + return RF_FAILURE; + break; + } + } + }// end of the exact string option + // success + return rfString_BytePosToCharPos(thisstr,bytepos,false); + } + + // else ignore case matching + uint32_t i,j; + // if(cstr[0] >= 0x41 && cstr[0] <= 0x5a) + for(i=0;ibyteLength; i ++) + { + // if i matches the start of the substring + for(j = 0; j < sstr->byteLength; j++) + { + // if the jth char is a big letter + if(sstr->bytes[j] >= 0x41 && sstr->bytes[j] <= 0x5a) + { + // no match + if(sstr->bytes[j] != thisstr->bytes[i+j] && sstr->bytes[j]+32 != thisstr->bytes[i+j]) + break; + // there is a match in the jth character so let's perform additional checks if needed + if(RF_BITFLAG_ON( options,RF_MATCH_WORD)) + { + // if it's the first substring character and if the string we search is not in it's beginning, check for EXACT string before + if(j == 0 && i != 0) + { + switch(thisstr->bytes[i-1]) + { + case ' ':case '\t':case '\n': + break; + default: + return RF_FAILURE; + break; + } + } + }// exact string check if ends + } + // small letter + else if(sstr->bytes[j] >= 0x61 && sstr->bytes[j] <= 0x7a) + { + // no match + if(sstr->bytes[j] != thisstr->bytes[i+j] && sstr->bytes[j]-32 != thisstr->bytes[i+j]) + break; + // there is a match in the jth character so let's perform additional checks if needed + if(RF_BITFLAG_ON(options,RF_MATCH_WORD)) + { + // if it's the first substring character and if the string we search is not in it's beginning, check for EXACT string before + if(j == 0 && i != 0) + { + switch(thisstr->bytes[i-1]) + { + case ' ':case '\t':case '\n': + break; + default: + return RF_FAILURE; + break; + } + } + }// exact string check if ends + } + // not a letter and no match + else if(sstr->bytes[j] != thisstr->bytes[i+j]) + break;// break off the substring search loop + + // if we get here and it's the last char of the substring we either found it or need to perform one last check for exact string + if(j == sstr->byteLength-1) + { + // only if the end of the string is not right after the substring + if( RF_BITFLAG_ON(options,RF_MATCH_WORD) && i+sstr->byteLength < thisstr->byteLength) + { + switch(thisstr->bytes[i+sstr->byteLength]) + { + case ' ':case '\t':case '\n': + break; + default: + return RF_FAILURE; + break; + } + }// end of the exact string check + // succes + return rfString_BytePosToCharPos(thisstr,i,false); + }// end of it's the last char of the substring check + }// substring iteration ends + }// this string iteration ends + return RF_FAILURE; +} + +// Returns the integer value of the string if and only if it contains only numbers. If it contains anything else the function fails. +char rfString_ToInt(void* str,int32_t* v) +{ + RF_String* thisstr = (RF_String*)str; + char* end; + // get the integer + *v = strtol ( thisstr->bytes, &end,10); + +// /This is the non-strict case. Takes the number out of the string no matter what else it has inside +/* // if we did get something + if(strlen(end) < this->length()) + return true; +*/ +// /This is the strict case, and the one we will go with. The non-strict case might be moved to its own function, if ever in the future + if(end[0] == '\0') + return true; + + // else false + return false; +} + +// Returns the float value of a String +int rfString_ToDouble(void* thisstrP,double* f) +{ + RF_String* str = (RF_String*)thisstrP; + *f = strtod(str->bytes,NULL); + // check the result + if(*f == 0.0) + { + // if it's zero and the string equals to zero then we are okay + if(rfString_Equal(str,RFS_("0")) || rfString_Equal(str,RFS_("0.0"))) + return RF_SUCCESS; + // underflow error + if(errno == ERANGE) + return RE_STRING_TOFLOAT_UNDERFLOW; + // in any other case it's a conversion error + return RE_STRING_TOFLOAT; + } + // if the result is a HUGE_VAL and errno is set,the number is not representable by a double + if(*f == HUGE_VAL && errno == ERANGE) + return RE_STRING_TOFLOAT_RANGE; + + // any other case success + return RF_SUCCESS; +} + +// Returns a cstring version of the string. +const char* rfString_ToCstr(const void* str) +{ + RF_String* thisstr = (RF_String*)str; + return thisstr->bytes; +} + +// Creates and returns an allocated copy of the given string +RF_String* rfString_Copy_OUT(void* srcP) +{ + RF_String* src = (RF_String*)srcP; + // create the new string + RF_String* ret; + RF_MALLOC(ret,sizeof(RF_String)); + // get the length + ret->byteLength = src->byteLength; + // copy the bytes + RF_MALLOC(ret->bytes,ret->byteLength+1); + memcpy(ret->bytes,src->bytes,ret->byteLength+1); + return ret; + +} +// Copies all the contents of a string to another +void rfString_Copy_IN(RF_String* dst,void* srcP) +{ + RF_String* src = (RF_String*)srcP; + // get the length + dst->byteLength = src->byteLength; + // copy the bytes + RF_MALLOC(dst->bytes,src->byteLength+1); + memcpy(dst->bytes,src->bytes,dst->byteLength+1); + return; + +} +// Copies a certain number of characters from a string +void rfString_Copy_chars(RF_String* dst,void* srcP,uint32_t charsN) +{ + uint32_t i = 0,bytePos; + RF_String* src = (RF_String*)srcP; + + // find the byte position until which we need to copy + RF_STRING_ITERATE_START(src,i,bytePos) + if(i == charsN) + break; + RF_STRING_ITERATE_END(i,bytePos) + dst->byteLength = bytePos; + RF_MALLOC(dst->bytes,dst->byteLength+1); + memcpy(dst->bytes,src->bytes,dst->byteLength+1); + dst->bytes[dst->byteLength] = '\0';// null terminate it +} + + +// Applies a limited version of sscanf after the specified substring +char i_rfString_ScanfAfter(void* str,void* afterstrP,const char* format,void* var) +{ + RF_String* thisstr = (RF_String*)str; + RF_String* afterstr = (RF_String*)afterstrP; + // return false if the substring is not found + char* found,*s; + if( (found = strstr(thisstr->bytes,afterstr->bytes)) ==0 ) + { + return false; + } + // get a pointer to the start of the position where sscanf will be used + s = thisstr->bytes + (found-thisstr->bytes+afterstr->byteLength); + + // use sscanf + if(sscanf(s,format,var) <=0) + { + return false; + } + return true; +} + +// Counts how many times a substring s occurs inside the string +int32_t i_rfString_Count(void* str,void* sstr2,const char* optionsP) +{ + RF_String* thisstr = (RF_String*)str; + RF_String* sstr = (RF_String*)sstr2; + char options = *optionsP; + int32_t index = 0; + int32_t move; + int32_t n = 0; + + // as long as the substring is found in the string + while ((move = rfString_FindBytePos(thisstr,sstr,options)) != RF_FAILURE) + { + move+= sstr->byteLength; + // proceed searching inside the string and also increase the counter + n++; + thisstr->bytes+=move; + index +=move; + thisstr->byteLength -=move; + } + + // return string to its original state and return the number of occurences, also returns 0 if not found + thisstr->bytes-=index; + thisstr->byteLength += index; + // success + return n; +} + +// Tokenizes the given string. Separates it into @c tokensN depending on how many substrings can be created from the @c sep separatior and stores them +// into the Array of RF_String* that should be passed to the function +i_DECLIMEX_ char rfString_Tokenize(void* str,char* sep,uint32_t* tokensN,RF_String** tokens) +{ + RF_String* thisstr = (RF_String*)str; + uint32_t i; + // first find the occurences of the separator, and then the number of tokens + *tokensN = rfString_Count(thisstr,RFS_(sep),0)+1; + // error checking + if(*tokensN == 0) + return false; + + // allocate the tokens + RF_MALLOC(*tokens,sizeof(RF_String) *(*tokensN)); + // find the length of the separator + uint32_t sepLen = strlen(sep); + char* s,*e; + s = thisstr->bytes; + for(i = 0; i < (*tokensN)-1; i ++) + { + // find each substring + e = strstr(s,sep); + (*tokens)[i].byteLength = e-s; + RF_MALLOC((*tokens)[i].bytes,(*tokens)[i].byteLength+1); + // put in the data + strncpy((*tokens)[i].bytes,s,(*tokens)[i].byteLength); + // null terminate + (*tokens)[i].bytes[(*tokens)[i].byteLength] = '\0'; + + // prepare for next sub-string + s = e+sepLen; + + } + // /make sure that if it's the last substring we change strategy + (*tokens)[i].byteLength = strlen(s); + RF_MALLOC((*tokens)[i].bytes,(*tokens)[i].byteLength+1); + // put in the data + strncpy((*tokens)[i].bytes,s,(*tokens)[i].byteLength); + // null terminate + (*tokens)[i].bytes[(*tokens)[i].byteLength] = '\0'; + + // success + return true; +} +// Initializes the given string as the first substring existing between the left and right parameter substrings. +char i_rfString_Between(void* thisstrP,void* lstrP,void* rstrP,RF_String* result,const char* optionsP) +{ + int32_t start,end; + RF_String* thisstr = (RF_String*)thisstrP; + RF_String* lstr = (RF_String*)lstrP; + RF_String* rstr = (RF_String*)rstrP; + char options = *optionsP; + RF_String temp; + // find the left substring + if( (start = rfString_FindBytePos(thisstr,lstr,options))== RF_FAILURE) + { + return false; + } + // get what is after it + rfString_After(thisstr,lstr,&temp,options); + // find the right substring in the remaining part + if( (end = rfString_FindBytePos(&temp,rstr,options))== RF_FAILURE) + { + return false; + } + // free temp string + rfString_Deinit(&temp); + // initialize the string to return + result->byteLength = end; + RF_MALLOC(result->bytes,result->byteLength+1); + memcpy(result->bytes,thisstr->bytes+start+lstr->byteLength,result->byteLength+1); + result->bytes[end]= '\0'; + // success + return true; +} + +// Initializes the given string as the substring from the start until any of the given Strings are found. +#ifndef RF_OPTION_DEFAULT_ARGUMENTS +char rfString_Beforev(void* thisstrP,RF_String* result,const char* optionsP,const unsigned char* parNP, ...) +#else +char i_rfString_Beforev(void* thisstrP,RF_String* result,const char* optionsP,const unsigned char* parNP, ...) +#endif +{ + RF_String* thisstr = (RF_String*)thisstrP; + RF_String* s; + char options = *optionsP; + unsigned char parN = *parNP; + int32_t i,minPos,thisPos; + // will keep the argument list + va_list argList; + // get the parameter characters + va_start(argList,parNP); + + minPos = 9999999; + for(i = 0; i < parN; i++) + { + s = (RF_String*) va_arg(argList,RF_String*); + if( (thisPos= rfString_FindBytePos(thisstr,s,options))!= RF_FAILURE) + { + if(thisPos < minPos) + minPos = thisPos; + } + } + va_end(argList); + + // if it is not found + if(minPos == 9999999) + { + return false; + } + // if it is found initialize the substring + result->byteLength = minPos; + RF_MALLOC(result->bytes,minPos+1); + memcpy(result->bytes,thisstr->bytes,minPos); + result->bytes[minPos] = '\0'; + // success + return true; +} + +// Initializes the given string as the substring from the start until the given string is found +char i_rfString_Before(void* thisstrP,void* sstrP,RF_String* result,const char* optionsP) +{ + RF_String* thisstr = (RF_String*)thisstrP; + RF_String* sstr = (RF_String*) sstrP; + char options = *optionsP; + int32_t ret; + // find the substring + if( (ret = rfString_FindBytePos(thisstr,sstr,options)) == RF_FAILURE) + { + return false; + } + // if it is found get the result initialize the substring + result->byteLength = ret; + RF_MALLOC(result->bytes,result->byteLength+1); + memcpy(result->bytes,thisstr->bytes,result->byteLength); + result->bytes[result->byteLength] = '\0'; + // success + return true; +} + + +// Initializes the given String with the substring located after (and not including) the after substring inside the parameter string. If the substring is not located the function returns false. +char i_rfString_After(void* thisstrP,void* afterP,RF_String* out,const char* optionsP) +{ + RF_String* thisstr = (RF_String*)thisstrP; + RF_String* after = (RF_String*)afterP; + char options = *optionsP; + int32_t bytePos; + // check for substring existence + if( (bytePos = rfString_FindBytePos(thisstr,after,options)) == RF_FAILURE) + { + return false; + } + // done so let's get it. Notice the use of the non-checking initialization + rfString_Init_nc(out,thisstr->bytes+bytePos+after->byteLength); + // success + return true; +} + + +// Initialize a string after the first of the given substrings found +#ifndef RF_OPTION_DEFAULT_ARGUMENTS +char rfString_Afterv(void* thisstrP,RF_String* result,const char* optionsP,const unsigned char* parNP,...) +#else +char i_rfString_Afterv(void* thisstrP,RF_String* result,const char* optionsP,const unsigned char* parNP,...) +#endif +{ + RF_String* thisstr = (RF_String*)thisstrP; + RF_String* s; + char options = *optionsP; + unsigned char parN = *parNP; + int32_t i,minPos,thisPos; + uint32_t minPosLength; + // will keep the argument list + va_list argList; + // get the parameter characters + va_start(argList,parNP); + + minPos = 9999999; + for(i = 0; i < parN; i++) + { + s = (RF_String*) va_arg(argList,RF_String*); + if( (thisPos= rfString_FindBytePos(thisstr,s,options))!= RF_FAILURE) + { + if(thisPos < minPos) + { + minPos = thisPos; + minPosLength = s->byteLength; + } + } + } + va_end(argList); + // if it is not found + if(minPos == 9999999) + { + return false; + } + // if it is found initialize the substring + minPos += minPosLength;// go after the found substring + result->byteLength = thisstr->byteLength-minPos; + RF_MALLOC(result->bytes,result->byteLength); + memcpy(result->bytes,thisstr->bytes+minPos,result->byteLength); + result->bytes[result->byteLength] = '\0'; + // success + return true; +} + +/*------------------------------------------------------------------------ RF_String manipulation functions-------------------------------------------------------------------------------*/ + + +// Appends the parameter String to this one +void i_rfString_Append(RF_String* thisstr,void* otherP) +{ + RF_String* other = (RF_String*)otherP; + // /@note Here if a null addition is given lots of actions are done but the result is safe and the same string as the one entered. + // /A check here would result in an additional check for every appending so I decided against it + // calculate the new length + thisstr->byteLength +=other->byteLength; + // reallocate this string to fit the new addition + RF_REALLOC(thisstr->bytes,char,thisstr->byteLength+1); + // add the string to this one + strncat(thisstr->bytes,other->bytes,other->byteLength); +} + +// Appends an integer to the string +void rfString_Append_i(RF_String* thisstr,const int32_t i) +{ + // create a new buffer for the string big enough to fit any number plus the original string + char* buff; + RF_MALLOC(buff,thisstr->byteLength+15);// max uint32_t is 4,294,967,295 in most environment so 12 chars will certainly fit it + // put the int32_t inside the string + sprintf(buff,"%s%i",thisstr->bytes,i); + // free the previous c string + free(thisstr->bytes); + // point the string pointer to the new string + thisstr->bytes = buff; + thisstr->byteLength = strlen(thisstr->bytes); +} +// Appends a float to the string. Can't be used with RF_StringX +void rfString_Append_f(RF_String* thisstr,const float f) +{ + // a temporary buffer to hold the float and the string + char* buff; + RF_MALLOC(buff,thisstr->byteLength+64); + // put the float inside the string + sprintf(buff,"%s%f",thisstr->bytes,f); + // free the previous c string + free(thisstr->bytes); + // point the string pointer to the new string + thisstr->bytes = buff; + thisstr->byteLength = strlen(thisstr->bytes); +} + +// Prepends the parameter String to this string +void i_rfString_Prepend(RF_String* thisstr,void* otherP) +{ + RF_String* other = (RF_String*)otherP; + uint32_t size; + int32_t i;// is not unsigned since it goes to -1 in the loop + // keeep the original byte size of the string + size = thisstr->byteLength; + // calculate the new lengths + thisstr->byteLength += other->byteLength; + // reallocate this string to fit the new addition + RF_REALLOC(thisstr->bytes,char,thisstr->byteLength+1); + // move the pre-existing string to the end of the buffer, by dislocating each byte by cstrlen + for(i =size; i >=0 ; i--) + thisstr->bytes[i+other->byteLength] = thisstr->bytes[i]; + // and now add the new string to the start + memcpy(thisstr->bytes,other->bytes,other->byteLength); +} + +// Removes all of the specifed string occurences from this String matching case or not, DOES NOT reallocate buffer size. +char i_rfString_Remove(void* thisstrP,void* rstrP,uint32_t* numberP,const char* optionsP) +{ + RF_String* thisstr = (RF_String*)thisstrP; + RF_String* rstr = (RF_String*)rstrP; + char options = *optionsP; + uint32_t number = *numberP; + uint32_t i,count,occurences=0; + int32_t bytePos; + char found = false; + // as long as we keep finding rstr in the string keep removing it + do + { // if the substring is not found + if( (bytePos = rfString_FindBytePos(thisstr,rstr,options)) == RF_FAILURE) + { + // if we have not even found it once , we fail + if(found == false) + { + return false; + } + else // else we are done + break; + } + + // substring found + found = true; + // move all of the string a position back + count = 0; + for(i = bytePos; i <=thisstr->byteLength; i ++) + { + thisstr->bytes[i] = thisstr->bytes[i+rstr->byteLength]; + count++; + } + // now change the byte length + thisstr->byteLength -= rstr->byteLength; + // count the number of occurences and if we reached the required amount, stop + occurences++; + if(occurences == number) + break; + }while(bytePos != RF_FAILURE); + // succcess + return true; +} + +// Removes all of the characters of the string except those specified +void i_rfString_KeepOnly(void* thisstrP,void* keepstrP) +{ + uint32_t keepLength,i,j,charValue,temp; + uint32_t *keepChars; + RF_String* thisstr = (RF_String*)thisstrP; + RF_String* keepstr = (RF_String*)keepstrP; + char exists,charBLength; + // first let's get all of the characters of the keep string in an array + i=0; + keepLength = rfString_Length(keepstr); + RF_MALLOC(keepChars,4*keepLength); + rfString_Iterate_Start(keepstr,i,charValue) + keepChars[i] = charValue; + rfString_Iterate_End(i) + // now iterate every character of this string + i=0; + rfString_Iterate_Start(thisstr,i,charValue) + // for every character check if it exists in the keep str + exists = false; + for(j=0;jbytes+byteIndex_,thisstr->bytes+byteIndex_+charBLength,thisstr->byteLength-byteIndex_+charBLength); + thisstr->byteLength-=charBLength; + continue;// by contiuing here we make sure that the current string position won't be moved to assure that we also check the newly move characters + } + rfString_Iterate_End(i) + // before returning free the keep string's character array + free(keepChars); +} + +// Removes the first n characters from the start of the string +char rfString_PruneStart(void* thisstrP,uint32_t n) +{ + RF_String* thisstr = (RF_String*)thisstrP; + // iterate the characters of the string + uint32_t i; + uint32_t length = 0; + unsigned nBytePos = 0; + char found = false; + RF_STRING_ITERATE_START(thisstr,length,i); + // if we reach the number of characters passed as a parameter, note it + if(length == n) + { + // remember that now i is the byte position we need + nBytePos = i; + found = true; + break; + } + RF_STRING_ITERATE_END(length,i) + + // if the string does not have n chars to remove it becomes an empty string and we return failure + if(found == false) + { + thisstr->bytes[0] = '\0'; + thisstr->byteLength = 0; + return false; + } + + // move the string back to cover the empty places.reallocation here would be an overkill, everything will be freed together when the string gets freed + for(i =0; i < thisstr->byteLength-nBytePos+1;i++ ) + thisstr->bytes[i] = thisstr->bytes[i+nBytePos]; + + // get the new bytelength + thisstr->byteLength -= nBytePos; + + return true; +} + +// Removes the last n characters from the end of the string +char rfString_PruneEnd(void* thisstrP,uint32_t n) +{ + RF_String* thisstr = (RF_String*)thisstrP; + // start the iteration of the characters from the end of the string + int32_t nBytePos = -1; + uint32_t length,i; + RF_STRING_ITERATEB_START(thisstr,length,i) + // if we found the requested number of characters from the end of the string + if(length == n) + { + // remember that now i is the byte position we need + nBytePos = i; + break; + } + RF_STRING_ITERATEB_END(length,i) + + // if the string does not have n chars to remove it becomes an empty string and we return failure + if(nBytePos == -1) + { + thisstr->bytes[0] = '\0'; + return false; + } + + // just set the end of string character characters back, reallocation here would be an overkill, everything will be freed together when the string gets freed + thisstr->bytes[nBytePos] = '\0'; + // and also set the new byte length + thisstr->byteLength -= (thisstr->byteLength - nBytePos); + // success + return true; +} + +// Removes n characters from the position p of the string counting backwards. If there is no space to do so, nothing is done and returns false. +char rfString_PruneMiddleB(void* thisstrP,uint32_t p,uint32_t n) +{ + RF_String* thisstr = (RF_String*)thisstrP; + // if we ask to remove more characters from the position that it would be possible do nothign and return false + if(n>p+1) + return false; + + // iterate the characters of the string + uint32_t j,i,length; + int32_t pBytePos,nBytePos; + pBytePos = nBytePos = -1; + RF_STRING_ITERATE_START(thisstr,length,i) + // if we reach the number of characters passed as a parameter, note it + if(length == p+1) + { + // we search for p+1 because we want to include all of the p character + pBytePos = i; + // also break since we don't care after position p + break; + } + if(length == p-n+1)// +1 is to make sure that indexing works from 0 + nBytePos = i; + + RF_STRING_ITERATE_END(length,i) + + // if the position was not found in the string do nothing + if(pBytePos == -1 || nBytePos == -1) + return false; + + // move the bytes in the buffer to remove the requested characters + for(i=nBytePos,j=0;j<= thisstr->byteLength-pBytePos+1; i ++,j++) // here +2 is for (+1 for pbytePos to go to the start of pth character) (+1 for the byteLength to include the null termination character) + { + thisstr->bytes[i] = thisstr->bytes[pBytePos+j]; + } + + // find the new byte length + thisstr->byteLength -= (nBytePos - pBytePos); + + return true; +} + +// Removes n characters from the position p of the string counting forwards. If there is no space, nothing is done and returns false. +char rfString_PruneMiddleF(void* thisstrP,uint32_t p,uint32_t n) +{ + RF_String* thisstr = (RF_String*)thisstrP; + // iterate the characters of the string + uint32_t j,i,length; + int32_t pBytePos,nBytePos; + pBytePos = nBytePos = -1; + RF_STRING_ITERATE_START(thisstr,length,i) + // if we reach the number of characters passed as a parameter, note it + if(length == p) + pBytePos = i; + + if(length == p+n) + { + nBytePos = i; + break;// since we got all the data we needed + } + + RF_STRING_ITERATE_END(length,i) + + // if the position was not found in the string do nothing + if(pBytePos == -1 ) + return false; + + // if we did not find the byte position of p+n then we remove everything from pBytePos until the end of the string + if(nBytePos == -1) + { + thisstr->bytes[pBytePos] = '\0'; + thisstr->byteLength -= (thisstr->byteLength-pBytePos); + return true; + } + + // move the bytes in the buffer to remove the requested characters + for(i=pBytePos,j=0;j<= thisstr->byteLength-nBytePos+1; i ++,j++) // here +2 is for (+1 for pbytePos to go to the start of pth character) (+1 for the byteLength to include the null termination character) + { + thisstr->bytes[i] = thisstr->bytes[nBytePos+j]; + } + + // find the new byte length + thisstr->byteLength -= (nBytePos - pBytePos); + return true; +} + +// Replaces all of the specified sstr substring from the String with rstr and reallocates size, unless the new size is smaller +char i_rfString_Replace(RF_String* thisstr,void* sstrP,void* rstrP,const uint32_t* numP,const char* optionsP) +{ + RF_String* sstr = (RF_String*)sstrP; + RF_String* rstr = (RF_String*)rstrP; + char options = *optionsP; + uint32_t num = *numP; + RF_StringX temp;// just a temporary string for finding the occurences + // will keep the number of found instances of the substring + uint32_t foundN = 0; + // will keep the number of given instances to find + uint32_t number = num; + uint32_t diff,i,j; + // if the substring string is not even found return false + if(rfString_FindBytePos(thisstr,sstr,options) == RF_FAILURE) + { + return false; + } + // create a buffer that will keep the byte positions + uint32_t bSize = 50; + int32_t * bytePositions; + RF_MALLOC(bytePositions,bSize*sizeof(int32_t)); + // if the given num is 0 just make sure we replace all + if(number == 0) + number = 999999;// max number of occurences + + // find how many occurences exist + rfStringX_FromString_IN(&temp,thisstr); + while( (bytePositions[foundN] = rfString_FindBytePos(&temp,sstr,options)) != RF_FAILURE) + { + int32_t move = bytePositions[foundN] + sstr->byteLength; + bytePositions[foundN] = bytePositions[foundN]+temp.bIndex; + temp.bIndex += move; + temp.bytes += move; + temp.byteLength -= move; + foundN++; + // if buffer is in danger of overflow realloc it + if(foundN > bSize) + { + bSize *=2; + RF_REALLOC(bytePositions,int32_t,bSize); + } + // if we found the required number of occurences break; + if(foundN >= number) + break; + } + rfStringX_Deinit(&temp); + // make sure that the number of occurence to replace do not exceed the actual number of occurences + if(number > foundN) + number = foundN; + // act depending on the size difference of rstr and sstr + if(rstr->byteLength > sstr->byteLength) // replace string is bigger than the removed one + { + int32_t orSize,nSize; + + diff = rstr->byteLength - sstr->byteLength; + // will keep the original size in bytes + orSize = thisstr->byteLength +1; + // reallocate the string to fit the new bigger size + nSize= orSize + number*diff; + RF_REALLOC(thisstr->bytes,char,nSize) + // now replace all the substrings one by one + for(i = 0; i < number; i ++) + { + // move all of the contents of the string to fit the replacement + for(j =orSize+diff-1; j > bytePositions[i]+sstr->byteLength; j -- ) + thisstr->bytes[j] = thisstr->bytes[j-diff]; + // copy in the replacement + strncpy(thisstr->bytes+bytePositions[i],rstr->bytes,rstr->byteLength); + // also increase the original size (since now we moved the whole string by one replacement) + orSize += diff; + // also increase all the subsequent found byte positions since there is a change of string size + for(j = i+1; j < number; j ++) + bytePositions[j] = bytePositions[j]+diff; + + } + // finally let's keep the new byte length + thisstr->byteLength = nSize-1; + } + else if( rstr->byteLength < sstr->byteLength) // replace string is smaller than the removed one + { + // get the differenc in byte length of removed substring and replace string + diff = sstr->byteLength-rstr->byteLength; + + // now replace all the substrings one by one + for(i =0; i < number; i ++) + { + // copy in the replacement + strncpy(thisstr->bytes+bytePositions[i],rstr->bytes,rstr->byteLength); + // move all of the contents of the string to fit the replacement + for(j =bytePositions[i]+rstr->byteLength; j < thisstr->byteLength; j ++ ) + thisstr->bytes[j] = thisstr->bytes[j+diff]; + // also decrease all the subsequent found byte positions since there is a change of string size + for(j = i+1; j < number; j ++) + bytePositions[j] = bytePositions[j]-diff; + } + // finally let's keep the new byte length + thisstr->byteLength -= diff*number; + // just note that reallocating downwards is not necessary + } + else // replace and remove strings are equal + { + for(i = 0; i < number; i ++) + strncpy(thisstr->bytes+bytePositions[i],rstr->bytes,rstr->byteLength); + } + free(bytePositions); + // success + return true; +} + +// Removes all characters of a substring only from the start of the String +char i_rfString_StripStart(void* thisstrP,void* subP) +{ + RF_String* thisstr = (RF_String*) thisstrP; + RF_String*sub = (RF_String*) subP; + char ret = false,noMatch; + uint32_t charValue,i = 0,*subValues,j,subLength,bytePos; + + // firstly get all of the characters of the substring in an array + subLength = rfString_Length(sub); + RF_MALLOC(subValues,4*subLength) + rfString_Iterate_Start(sub,i,charValue) + subValues[i] = charValue; + rfString_Iterate_End(i) + + // iterate thisstring from the beginning + i = 0; + RF_STRING_ITERATE_START(thisstr,i,bytePos) + noMatch = true; + // for every substring character + for(j = 0;j < subLength; j++) + { + // if we got a match + if(rfString_BytePosToCodePoint(thisstr,bytePos) == subValues[j]) + { + ret = true; + noMatch = false; + break; + } + } + // if we get out of iterating the substring without having found a match, we get out of the iteration in general + if(noMatch) + break; + RF_STRING_ITERATE_END(i,bytePos) + + // if we had any match + if(ret == true) + { + // remove the characters + for(i =0; i < thisstr->byteLength-bytePos+1;i++ ) + thisstr->bytes[i] = thisstr->bytes[i+bytePos]; + // also change bytelength + thisstr->byteLength -= bytePos; + } + // free stuff and return + free(subValues); + return ret; +} + +// Removes all characters of a substring starting from the end of the String +char i_rfString_StripEnd(void* thisstrP,void* subP) +{ + RF_String* thisstr = (RF_String*) thisstrP; + RF_String*sub = (RF_String*) subP; + char ret = false,noMatch; + uint32_t charValue,i = 0,*subValues,j,subLength,bytePos,lastBytePos,testity; + + // firstly get all of the characters of the substring in an array + subLength = rfString_Length(sub); + RF_MALLOC(subValues,4*subLength) + rfString_Iterate_Start(sub,i,charValue) + subValues[i] = charValue; + rfString_Iterate_End(i) + + // iterate thisstring from the end + i = 0; + RF_STRING_ITERATEB_START(thisstr,i,bytePos) + noMatch = true; + // for every substring character + for(j = 0;j < subLength; j++) + { + // if we got a match + if((testity=rfString_BytePosToCodePoint(thisstr,bytePos)) == subValues[j]) + { + ret = true; + noMatch = false; + lastBytePos = bytePos; + break; + } + } + // if we get out of iterating the substring without having found a match, we get out of the iteration in general + if(noMatch) + break; + RF_STRING_ITERATEB_END(i,bytePos) + + // if we had any match + if(ret == true) + { + // just set the end of string there + thisstr->bytes[lastBytePos] = '\0'; + // and also set the new byte length + thisstr->byteLength -= (thisstr->byteLength - lastBytePos); + } + + // free stuff and return + free(subValues); + return ret; +} + +// Removes all characters of a substring from both ends of the given String +char i_rfString_Strip(void* thisstrP,void* subP) +{ + char res1 = rfString_StripStart(thisstrP,subP); + char res2 = rfString_StripEnd(thisstrP,subP); + return res1|res2; +} + + +/*------------------------------------------------------------------------ RF_String File I/O functions-------------------------------------------------------------------------------*/ + +// Allocates and returns a string from file parsing. The file's encoding must be UTF-8.If for some reason (like EOF reached) no string can be read then null is returned +RF_String* rfString_Create_fUTF8(FILE* f, char* eof) +{ + RF_String* ret; + RF_MALLOC(ret,sizeof(RF_String)); + if(rfString_Init_fUTF8(ret,f,eof) < 0) + { + free(ret); + return 0; + } + return ret; +} +// Initializes a string from file parsing. The file's encoding must be UTF-8.If for some reason (like EOF reached) no string can be read then null is returned +int32_t rfString_Init_fUTF8(RF_String* str,FILE* f,char* eof) +{ + int32_t bytesN; + uint32_t bufferSize;// unused + if((bytesN=rfFReadLine_UTF8(f,&str->bytes,&str->byteLength,&bufferSize,eof)) < 0) + { + LOG_ERROR("Failed to initialize String from a UTF-8 file",bytesN); + return bytesN; + } + // success + return bytesN; +} +// Assigns to a String from UTF-8 file parsing +int32_t rfString_Assign_fUTF8(RF_String* str,FILE*f,char* eof) +{ + int32_t bytesN; + uint32_t utf8ByteLength,utf8BufferSize;// bufferSize unused in this function + char* utf8 = 0; + if((bytesN=rfFReadLine_UTF8(f,&utf8,&utf8ByteLength,&utf8BufferSize,eof)) < 0) + { + LOG_ERROR("Failed to assign the contents of a UTF-8 file to a String",bytesN); + return bytesN; + } + // success + // assign it to the string + if(str->byteLength <= utf8ByteLength) + { + RF_REALLOC(str->bytes,char,utf8ByteLength+1); + } + memcpy(str->bytes,utf8,utf8ByteLength+1); + str->byteLength = utf8ByteLength; + // free the file's utf8 buffer + free(utf8); + return bytesN; +} +// Appends to a String from UTF-8 file parsing +int32_t rfString_Append_fUTF8(RF_String* str,FILE*f,char* eof) +{ + int32_t bytesN; + uint32_t utf8ByteLength,utf8BufferSize;// bufferSize unused in this function + char* utf8 = 0; + if((bytesN=rfFReadLine_UTF8(f,&utf8,&utf8ByteLength,&utf8BufferSize,eof)) < 0) + { + LOG_ERROR("Failed to assign the contents of a UTF-8 file to a String",bytesN); + return bytesN; + } + // append the utf8 to the given string + rfString_Append(str,RFS_(utf8)); + // free the file's utf8 buffer + free(utf8); + return bytesN; +} + +// Allocates and returns a string from file parsing. The file's encoding must be UTF-16.If for some reason (like EOF reached) no string can be read then null is returned. A check for a valid sequence of bytes is performed. +RF_String* rfString_Create_fUTF16(FILE* f,char endianess,char* eof) +{ + RF_String* ret; + RF_MALLOC(ret,sizeof(RF_String)); + if(rfString_Init_fUTF16(ret,f,endianess,eof) < 0) + return 0; + return ret; +} +// Initializes a string from file parsing. The file's encoding must be UTF-16.If for some reason (like EOF reached) no string can be read then null is returned. A check for a valid sequence of bytes is performed. +int32_t rfString_Init_fUTF16(RF_String* str,FILE* f, char endianess,char* eof) +{ + int32_t bytesN; + // depending on the file's endianess + if(endianess == RF_LITTLE_ENDIAN) + { + if((bytesN=rfFReadLine_UTF16LE(f,&str->bytes,&str->byteLength,eof)) < 0) + { + LOG_ERROR("Failure to initialize a String from reading a UTF-16 file",bytesN); + return bytesN; + } + }// end of little endian + else// big endian + { + if((bytesN=rfFReadLine_UTF16BE(f,&str->bytes,&str->byteLength,eof)) < 0) + { + LOG_ERROR("Failure to initialize a String from reading a UTF-16 file",bytesN); + return bytesN; + } + }// end of big endian case + // success + return bytesN; +} + +// Assigns to an already initialized String from File parsing +int32_t rfString_Assign_fUTF16(RF_String* str,FILE* f, char endianess,char* eof) +{ + + uint32_t utf8ByteLength; + int32_t bytesN; + char* utf8 = 0; + // depending on the file's endianess + if(endianess == RF_LITTLE_ENDIAN) + { + if((bytesN=rfFReadLine_UTF16LE(f,&utf8,&utf8ByteLength,eof)) < 0) + { + LOG_ERROR("Failure to assign the contents of a Little Endian UTF-16 file to a String",bytesN); + return bytesN; + } + }// end of little endian + else// big endian + { + if((bytesN=rfFReadLine_UTF16BE(f,&utf8,&utf8ByteLength,eof)) < 0) + { + LOG_ERROR("Failure to assign the contents of a Big Endian UTF-16 file to a String",bytesN); + return bytesN; + } + }// end of big endian case + // success + // assign it to the string + if(str->byteLength <= utf8ByteLength) + { + RF_REALLOC(str->bytes,char,utf8ByteLength+1); + } + memcpy(str->bytes,utf8,utf8ByteLength+1); + str->byteLength = utf8ByteLength; + // free the file's utf8 buffer + free(utf8); + return bytesN; +} + +// Appends to an already initialized String from File parsing +int32_t rfString_Append_fUTF16(RF_String* str,FILE* f, char endianess,char* eof) +{ + char*utf8; + uint32_t utf8ByteLength; + int32_t bytesN; + // depending on the file's endianess + if(endianess == RF_LITTLE_ENDIAN) + { + if((bytesN=rfFReadLine_UTF16LE(f,&utf8,&utf8ByteLength,eof)) < 0) + { + LOG_ERROR("Failure to append the contents of a Little Endian UTF-16 file to a String",bytesN); + return bytesN; + } + }// end of little endian + else// big endian + { + if((bytesN=rfFReadLine_UTF16BE(f,&utf8,&utf8ByteLength,eof)) < 0) + { + LOG_ERROR("Failure to append the contents of a Big Endian UTF-16 file to a String",bytesN); + return bytesN; + } + }// end of big endian case + // success + rfString_Append(str,RFS_(utf8)); + free(utf8); + return bytesN; +} + +// Allocates and returns a string from file parsing. The file's encoding must be UTF-32.If for some reason (like EOF reached) no string can be read then null is returned. A check for a valid sequence of bytes is performed. +RF_String* rfString_Create_fUTF32(FILE* f,char endianess,char* eof) +{ + RF_String* ret; + RF_MALLOC(ret,sizeof(RF_String)); + if(rfString_Init_fUTF32(ret,f,endianess,eof) < 0) + { + free(ret); + return 0; + } + return ret; +} +// Initializes a string from file parsing. The file's encoding must be UTF-32.If for some reason (like EOF reached) no string can be read then null is returned. A check for a valid sequence of bytes is performed. +int32_t rfString_Init_fUTF32(RF_String* str,FILE* f,char endianess,char* eof) +{ + int32_t bytesN; + // depending on the file's endianess + if(endianess == RF_LITTLE_ENDIAN) + { + if((bytesN=rfFReadLine_UTF32LE(f,&str->bytes,&str->byteLength,eof)) <0) + { + LOG_ERROR("Failure to initialize a String from reading a Little Endian UTF-32 file",bytesN); + return bytesN; + } + }// end of little endian + else// big endian + { + if((bytesN=rfFReadLine_UTF16BE(f,&str->bytes,&str->byteLength,eof)) < 0) + { + LOG_ERROR("Failure to initialize a String from reading a Big Endian UTF-32 file",bytesN); + return bytesN; + } + }// end of big endian case + // success + return bytesN; +} +// Assigns the contents of a UTF-32 file to a string +int32_t rfString_Assign_fUTF32(RF_String* str,FILE* f,char endianess, char* eof) +{ + int32_t bytesN; + char*utf8; + uint32_t utf8ByteLength; + // depending on the file's endianess + if(endianess == RF_LITTLE_ENDIAN) + { + if((bytesN=rfFReadLine_UTF32LE(f,&utf8,&utf8ByteLength,eof)) < 0) + { + LOG_ERROR("Failure to assign to a String from reading a Little Endian UTF-32 file",bytesN); + return bytesN; + } + }// end of little endian + else// big endian + { + if((bytesN=rfFReadLine_UTF16BE(f,&utf8,&utf8ByteLength,eof)) < 0) + { + LOG_ERROR("Failure to assign to a String from reading a Big Endian UTF-32 file",bytesN); + return bytesN; + } + }// end of big endian case + // success + // assign it to the string + if(str->byteLength <= utf8ByteLength) + { + RF_REALLOC(str->bytes,char,utf8ByteLength+1); + } + memcpy(str->bytes,utf8,utf8ByteLength+1); + str->byteLength = utf8ByteLength; + // free the file's utf8 buffer + free(utf8); + return bytesN; +} +// Appends the contents of a UTF-32 file to a string +int32_t rfString_Append_fUTF32(RF_String* str,FILE* f,char endianess, char* eof) +{ + int32_t bytesN; + char*utf8; + uint32_t utf8ByteLength; + // depending on the file's endianess + if(endianess == RF_LITTLE_ENDIAN) + { + if((bytesN=rfFReadLine_UTF32LE(f,&utf8,&utf8ByteLength,eof)) < 0) + { + LOG_ERROR("Failure to append to a String from reading a Little Endian UTF-32 file",bytesN); + return bytesN; + } + }// end of little endian + else// big endian + { + if((bytesN=rfFReadLine_UTF16BE(f,&utf8,&utf8ByteLength,eof)) < 0) + { + LOG_ERROR("Failure to append to a String from reading a Big Endian UTF-32 file",bytesN); + return bytesN; + } + }// end of big endian case + // success + // append it + rfString_Append(str,RFS_(utf8)); + // free the file'sutf8 buffer + free(utf8); + return bytesN; +} + +// Writes a string to a file in UTF-8 encoding. +int32_t i_rfString_Fwrite(void* sP,FILE* f,char* encodingP) +{ + uint32_t *utf32,length,i; + uint16_t* utf16; + RF_String* s = (RF_String*)sP; + char encoding = *encodingP; + // depending on the encoding + switch(encoding) + { + case RF_UTF8: + if(fwrite(s->bytes,1,s->byteLength,f) != s->byteLength) + break;// and go to error logging + return RF_SUCCESS; + break; + case RF_UTF16_LE: + utf16 = rfString_ToUTF16(s,&length); + if(rfUTILS_Endianess() != RF_LITTLE_ENDIAN) + { + for(i=0;i + +#ifdef RF_MODULE_STRINGS// check if the strings are included as a module + +#include +#include + +#include // for the argument count +#include // for the local memory function wrapping functionality +#include // for unicode + + +#ifdef __cplusplus +extern "C" +{// opening bracket for calling from C++ +#endif + +// An option for some string functions. Means that the case should not be exactly matched in the string replacing,finding e.t.c. +#define RF_CASE_IGNORE 0x1 +// An options for some string functions. Means that the exact string should be found/replaced e.t.c. +#define RF_MATCH_WORD 0x2 + + +// Denotes that a requested character/byte index in an RF_String is out of bounds +#define RF_STRING_INDEX_OUT_OF_BOUNDS ((uint32_t)0xFF0FFFF) + +/* These are here so that the iteration macros can work*/ + +// Checks if a given byte is a continuation byte +#define rfUTF8_IsContinuationByte2(b__) ( b__ >= 0x80 && b__<= 0xBF ) + +#pragma pack(push,1) +/** +** @internal +** @author Lefteris +** @date 09/12/2010 +** @endinternal +** @brief A unicode String with UTF-8 internal representation +** +** The Refu String is a Unicode String that has two versions. One is this and for the other check @ref RF_StringX to see what operations can be performed on extended Strings. +** Functions to convert to and from all UTF encoding exists but the internal representation is always at UTF-8. Once a +** a String has been created it is always assumed that the stream of bytes inside it is valid UTF-8 since every function +** performs a UTF-8 check unless otherwise specified. +** +** All the functions which have @isinherited{StringX} on their description can be used with extended strings safely, since no specific +** version of the function exists, or needs to exist to manipulate Extended Strings. To make the documentation even clearer the functions that should not +** be used with the extended string are marked with @notinherited{StringX} +** @internal +** @cppcode +** //default constructor +** String(){this->i_StringCHandle = rfString_Create("");} +** @endcpp +** @endinternal +*/ +typedef struct RF_String +{ + // The string's data + char* bytes; + // The string's length in bytes (not including the null termination). The string keeps its length in bytes + // to avoid multiple calls to strlen() + uint32_t byteLength; +}RF_String; +#pragma pack(pop) + + +// @memberof RF_String +// @brief Create a termporary String from a String literal +// +// A macro to be used only inside a function call that accepts an @ref RF_String to create a Temporary RF_String* +// that will be used by the function. This macro accepts from 1 to N arguments. +// +// The first argument shall either be a String literal or a printf styled string literal +// given in the source file's encoding(default is UTF-8). For other encodings look at the compile time +// option @c RF_OPTION_SOURCE_ENCODING that can be provided during building the library, but it is +// @b strongly recommended to use UTF-8 encoded source files. +// +// Optionally the first argument can be followed by a sequence of additional arguments, +// each containing one value to be inserted instead of each %-tag specified in the string literal +// parameter, if any. There should be +// the same number of these arguments as the number of %-tags that expect a value. +// Basically the usage is the same as @ref rfString_Create +// +// @param s The formatted string that will constitute the RF_String. Must be in the same encoding as that of the source file. +// Default is UTF-8. +// @param ... \rfoptional{nothing} Depending on the string literal, the function may expect a sequence of additional arguments, +// each containing one value to be inserted instead of each %-tag specified in the @c slit parameter, if any. There should be +// the same number of these arguments as the number of %-tags that expect a value. +// @return Returns true in case of correct initialization and false , due to invalid byte sequence for the given encoding +// @isinherited{StringX} +#ifdef RF_IAMHERE_FOR_DOXYGEN +RF_String* RFS_(const char* s,...); +#else +#define RFS_(...) i_rfString_CreateLocal(__VA_ARGS__) +#endif + + + +/*-------------------------------------------------------------------------Methods to create an RF_String-------------------------------------------------------------------------------*/ +// @name Creating an RF_String +// @{ + + +// @memberof RF_String +// @opassign +// @brief Allocates and returns a string with the given characters +// +// Given characters have to be in UTF-8. A check for valid sequence of bytes is performed. @notinherited{StringX} +// @param s The sequence of bytes for the characters in UTF-8 (the default). Can also follow a printf-like format which will be formatted with +// the variables that follow it. A check to see if it is a valid UTF-8 sequence is performed +// @param ... \rfoptional{nothing} Depending on the string literal, the function may expect a sequence of additional arguments, +// each containing one value to be inserted instead of each %-tag specified in the @c slit parameter, if any. There should be +// the same number of these arguments as the number of %-tags that expect a value. +// @return Returns the initialized RF_string or null in case of failure to initialize, due to invalid utf-8 sequence +#ifndef RF_OPTION_DEFAULT_ARGUMENTS +i_DECLIMEX_ RF_String* rfString_Create(const char* s,...); +#else +i_DECLIMEX_ RF_String* i_rfString_Create(const char* s,...); +i_DECLIMEX_ RF_String* i_NVrfString_Create(const char* s); +#define rfString_Create(...) RP_SELECT_FUNC_IF_NARGIS(i_SELECT_RF_STRING_CREATE,1,__VA_ARGS__) +#define i_SELECT_RF_STRING_CREATE1(...) i_NVrfString_Create(__VA_ARGS__) +#define i_SELECT_RF_STRING_CREATE0(...) i_rfString_Create(__VA_ARGS__) +#endif + +///Internal function that creates a temporary RF_String* +i_DECLIMEX_ RF_String* i_rfString_CreateLocal1(const char* s,...); +i_DECLIMEX_ RF_String* i_NVrfString_CreateLocal(const char* s); +#define i_rfString_CreateLocal(...) RP_SELECT_FUNC_IF_NARGIS(i_SELECT_RF_STRING_CREATELOCAL,1,__VA_ARGS__) +#define i_SELECT_RF_STRING_CREATELOCAL1(...) i_NVrfString_CreateLocal(__VA_ARGS__) +#define i_SELECT_RF_STRING_CREATELOCAL0(...) i_rfString_CreateLocal1(__VA_ARGS__) + + +// @memberof RF_String +// @brief Initializes a string with the given characters. +// +// @notinherited{StringX} +// Given characters have to be in UTF-8. A check for valide sequence of bytes is performed. +// @param str The string to initialize +// @param s The sequence of bytes for the characters in UTF-8 (the default).Can also follow a printf-like format which will be formatted with +// the variables that follow it. A check to see if it is a valid UTF-8 sequence is performed +// @param ... \rfoptional{nothing} Depending on the string literal, the function may expect a sequence of additional arguments, +// each containing one value to be inserted instead of each %-tag specified in the @c slit parameter, if any. There should be +// the same number of these arguments as the number of %-tags that expect a value. +// @return Returns true in case of correct initialization and false , due to invalid utf-8 sequence +#ifndef RF_OPTION_DEFAULT_ARGUMENTS +i_DECLIMEX_ char rfString_Init(RF_String* str,const char* s,...); +#else +i_DECLIMEX_ char i_rfString_Init(RF_String* str,const char* s,...); +i_DECLIMEX_ char i_NVrfString_Init(RF_String* str,const char* s); +#define rfString_Init(...) RP_SELECT_FUNC_IF_NARGIS(i_SELECT_RF_STRING_INIT,2,__VA_ARGS__) +#define i_SELECT_RF_STRING_INIT1(...) i_NVrfString_Init(__VA_ARGS__) +#define i_SELECT_RF_STRING_INIT0(...) i_rfString_Init(__VA_ARGS__) +#endif + +// @memberof RF_String +// @cppnotctor +// @brief Allocates a String by turning a unicode code point in a String (encoded in UTF-8). +// +// @notinherited{StringX} +// @param code The unicode code point to encode +// @return A String with the code point encoded in it or a null pointer in case of an illegal code point value +i_DECLIMEX_ RF_String* rfString_Create_cp(uint32_t code); +// @memberof RF_String +// @brief Initializes a string by turning a unicode code point in a String (encoded in UTF-8). +// +// @notinherited{StringX} +// @param str The string to initialize +// @param code The unicode code point to encode +// @return Returns true in case of correct initialization and false , due to illegal code point value +i_DECLIMEX_ char rfString_Init_cp(RF_String* str,uint32_t code); + + +#ifndef RF_OPTION_DEFAULT_ARGUMENTS +// @memberof RF_String +// @cppnotctor +// @brief Allocates and returns a string with the given characters with no checking. +// +// @notinherited{StringX} +// @warning NO VALID-UTF8 check is performed. +// @param s The sequence of bytes for the characters in UTF-8 (the default).Can also follow a printf-like format which will be formatted with +// the variables that follow it. No check for valid bytestream is performed +// @param ... \rfoptional{nothing} Depending on the string literal, the function may expect a sequence of additional arguments, +// each containing one value to be inserted instead of each %-tag specified in the @c slit parameter, if any. There should be +// the same number of these arguments as the number of %-tags that expect a value. +// @return Returns the initialized RF_string or null in case of failure to initialize +i_DECLIMEX_ RF_String* rfString_Create_nc(const char* s,...); +#else +i_DECLIMEX_ RF_String* i_rfString_Create_nc(const char* s,...); +i_DECLIMEX_ RF_String* i_NVrfString_Create_nc(const char* s); +#define rfString_Create_nc(...) RP_SELECT_FUNC_IF_NARGIS(i_SELECT_RF_STRING_CREATE_NC,1,__VA_ARGS__) +#define i_SELECT_RF_STRING_CREATE_NC1(...) i_NVrfString_Create_nc(__VA_ARGS__) +#define i_SELECT_RF_STRING_CREATE_NC0(...) i_rfString_Create_nc(__VA_ARGS__) +#endif + +#ifndef RF_OPTION_DEFAULT_ARGUMENTS +// @memberof RF_String +// @brief Initializes a string with the given characters with no checking +// +// @notinherited{StringX} +// @warning NO VALID-UTF8 check is performed. +// @param str The string to initialize +// @param s The sequence of bytes for the characters in UTF-8 (the default).Can also follow a printf-like format which will be formatted with +// the variables that follow it. No check for valid bytestream is performed +// @param ... \rfoptional{nothing} Depending on the string literal, the function may expect a sequence of additional arguments, +// each containing one value to be inserted instead of each %-tag specified in the @c slit parameter, if any. There should be +// the same number of these arguments as the number of %-tags that expect a value. +// @return Returns true in case of correct initialization and false otherwise +i_DECLIMEX_ char rfString_Init_nc(RF_String* str,const char* s,...); +#else +i_DECLIMEX_ char i_rfString_Init_nc(RF_String* str,const char* s,...); +i_DECLIMEX_ char i_NVrfString_Init_nc(RF_String* str,const char* s); +#define rfString_Init_nc(...) RP_SELECT_FUNC_IF_NARGIS(i_SELECT_RF_STRING_INIT_NC,2,__VA_ARGS__) +#define i_SELECT_RF_STRING_INIT_NC1(...) i_NVrfString_Init_nc(__VA_ARGS__) +#define i_SELECT_RF_STRING_INIT_NC0(...) i_rfString_Init_nc(__VA_ARGS__) +#endif + +// @memberof RF_String +// @opassign +// @brief Allocates and returns a string with the given integer. +// +// @notinherited{StringX} +// @param i The integer to turn into a string +// @return Returns the initialized RF_string +i_DECLIMEX_ RF_String* rfString_Create_i(int32_t i); +// @memberof RF_String +// @brief Initializes a string with the given integer. +// +// @notinherited{StringX} +// @param str The string to initialize +// @param i The integer to turn into a string +// @return Returns true in case of correct initialization and false otherwise +i_DECLIMEX_ char rfString_Init_i(RF_String* str,int32_t i); +// @memberof RF_String +// @opassign +// @brief Allocates and returns a string with the given float. +// +// @notinherited{StringX} +// @param f The float to turn into a string +// @return Returns the initialized RF_string +i_DECLIMEX_ RF_String* rfString_Create_f(float f); +// @memberof RF_String +// @brief Initializes a string with the given float. +// +// @notinherited{StringX} +// @param str The string to initialize +// @param f The float to turn into a string +// @return Returns true in case of correct initialization and false otherwise +i_DECLIMEX_ char rfString_Init_f(RF_String* str,float f); + +// @memberof RF_String +// @brief Allocates and returns a string with the given UTF-16 byte sequence. +// +// @notinherited{StringX} +// Given characters have to be in UTF-16 +// @param s The sequence of bytes for the characters in UTF-16. +// @param endianess A flag that determined in what endianess the sequence of UTF-16 bytes is in. Possible values here is +// @c RF_LITTLE_ENDIAN and @c RF_BIG_ENDIAN. +// @return Returns the initialized RF_string or null in case of failure to initialize, due to invalid utf-16 sequence or illegal endianess value +i_DECLIMEX_ RF_String* rfString_Create_UTF16(const char* s,char endianess); +// @memberof RF_String +// @brief Initializes a string with the given UTF-16 byte sequence. +// +// @notinherited{StringX} +// Given characters have to be in UTF-16 +// @param str The string to initialize +// @param s The sequence of bytes for the characters in UTF-16. +// @param endianess A flag that determined in what endianess the sequence of UTF-16 bytes is in. Possible values here is +// @c RF_LITTLE_ENDIAN and @c RF_BIG_ENDIAN. +// @return Returns true for succesfull initialization and false otherwise due to invalid utf-16 sequence or illegal endianess value +i_DECLIMEX_ char rfString_Init_UTF16(RF_String* str,const char* s,char endianess); + +// @memberof RF_String +// @cppnotctor +// @brief Allocates and returns a string with the given UTF-32 byte sequence. +// +// @notinherited{StringX} +// Given characters have to be in UTF-32 +// @param s The sequence of bytes for the characters in UTF-32. Needs to be null terminated. +// @return Returns the initialized RF_string or null in case of failure to initialize +i_DECLIMEX_ RF_String* rfString_Create_UTF32(const char* s); +// @memberof RF_String +// @brief Initializes a string with the given UTF-32 byte sequence. +// +// @notinherited{StringX} +// Given characters have to be in UTF-32 +// @param str The string to initialize +// @param s The sequence of bytes for the characters in UTF-32. Needs to be null terminated. +// @return Returns true for successful initialization and false otherwise +i_DECLIMEX_ char rfString_Init_UTF32(RF_String* str,const char* s); +//@} + +/*-------------------------------------------------------------------------Methods to copy/assign an RF_String-------------------------------------------------------------------------------*/ +// @name Copying - Assigning a String +// @{ + +// @memberof RF_String +// @brief Assigns the value of the source string to the destination. +// +// @notinherited{StringX} +// @lmsFunction +// Both strings should already be initialized and hold a value. It is an error to give null parameters. +// @param dest The destination string, which should get assigned +// @param source The source string, whose values to copy. @inhtype{String,StringX} @tmpSTR +#if defined(RF_IAMHERE_FOR_DOXYGEN) +void rfString_Assign(RF_String* dest,void* source); +#else +i_DECLIMEX_ void i_rfString_Assign(RF_String* dest,void* source); +#define rfString_Assign(i_DESTINATION_,i_SOURCE_) i_rfLMS_WRAP2(void,i_rfString_Assign,i_DESTINATION_,i_SOURCE_) +#endif + +// @memberof RF_String +// @brief Assigns the value of a unicode character to the string +// +// @notinherited{StringX} +// @param thisstr The string to assign to +// @param character The unicode character codepoint to assign to the String +// @return Returns @c true for succesfull assignment and @c false if the given @c character was not a valid unicode codepoint +i_DECLIMEX_ char rfString_Assign_char(RF_String* thisstr,uint32_t character); + +// @} +/*-------------------------------------------------------------------------Methods to get rid of an RF_String-------------------------------------------------------------------------------*/ +// @name Getting rid of an RF_String +// @{ + +// @memberof RF_String +// @cppignore +// @brief Deletes a string object and also frees its pointer. +// +// @notinherited{StringX} +// It is an error to give a NULL(0x0) string for deleting. Will most probably lead to a segmentation fault +// Use it for strings made with _Create +// @param s The string for deletion +i_DECLIMEX_ void rfString_Destroy(RF_String* s); +// @memberof RF_String +// @cppignore +// @brief Deletes a string object only, not its memory. +// +// @notinherited{StringX} +// It is an error to give a NULL(0x0) string for deleting. Will most probably lead to a segmentation fault +// Use it for strings made with _Init +// @param s The string for deletion +i_DECLIMEX_ void rfString_Deinit(RF_String* s); + + +// @} +/*------------------------------------------------------------------------ RF_String unicode conversion-------------------------------------------------------------------------------*/ +// @name Unicode Conversion Functions +// @{ + +// @memberof RF_String +// @brief Returns the strings contents as a UTF-8 buffer +// +// @isinherited{StringX} +// This is just a macro wrapper of @ref rfString_ToStr() and exists here +// just so that users can guess function names for all unicode encodings. +// +// Note that just like in @ref rfString_ToStr() this is just a pointer to +// the String's internal UTF8 buffer and as such should be read only. If there +// is a need to do anything other than that copy the buffer. +// @param s The string in question +// @return Returns a pointer to the String's internal UTF-8 uffer +#if defined(RF_IAMHERE_FOR_DOXYGEN) +i_DECLIMEX_ const char* rfString_ToUTF8(RF_String* s); +#else +#define rfString_ToUTF8(i_STRING_) rfString_ToCstr(i_STRING_) +#endif + +// @memberof RF_String +// @brief Returns the strings contents as a UTF-16 buffer +// +// @isinherited{StringX} +// This function allocates a UTF-16 buffer in which the string's +// UTF-8 contents are encoded as UTF-16. The endianess of the buffer +// is that of the system. The returned buffer needs to be freed by the user +// later. +// @param[in] s The string in question +// @param[out] length Give a reference to a uint32_t in this argument to receive the length of +// the returned UTF-16 buffer in 16-bit words +// @return Returns an allocated UTF-16 buffer. Needs to be freed by the user later. +i_DECLIMEX_ uint16_t* rfString_ToUTF16(RF_String* s,uint32_t* length); + +// @memberof RF_String +// @brief Returns the strings contents as a UTF-32 buffer +// +// @isinherited{StringX} +// This function allocates a UTF-32 buffer in which the string's +// UTF-8 contents are encoded as UTF-32. The endianess of the buffer +// is that of the system. The returned buffer needs to be freed by the user +// later. +// @param[in] s The string in question +// @param[out] length Give a reference to a uint32_t in this argument to receive the length +// of the returned UTF-32 buffer in codepoints. (32-bit) words +// @return Returns an allocated UTF-16 buffer. Needs to be freed by the user later. +i_DECLIMEX_ uint32_t* rfString_ToUTF32(RF_String* s,uint32_t*length); + +// @} +/*------------------------------------------------------------------------ RF_String retrieval functions-------------------------------------------------------------------------------*/ +// @name String Retrieval +// @{ + + + + //-- String iteration --/ / + +// Two macros to accomplish iteration of an RF_String from any given character going forwards. This macro should be used with its end pair. +// We take advantage of the fact that an RF_String is always guaranteed to contain a valid UTF-8 sequence and thus no checks are performed. +/** +** @memberof RF_String +** @cppignore +** @brief Starts an RF_String forward iteration scope. +** +** @isinherited{StringX} +** Use this macro to iterate every character inside an RF_String or RF_StringX\n +** Must be used with its pair macro #rfString_Iterate_End.\n +** As an example consider this code that iterates every character of a string from the start to finish +** @code +** uint32_t i = 0; +** uint32_t charValue; +** RF_String foo;rfString_Init(&foo,"I am a String"); +** rfString_Iterate_Start(&foo,i,charValue) +** //for every character in the string,let's print it +** printf("Character at index %d is %c\n",i,charValue); +** rfString_Iterate_End(i) +** @endcode +** @param[in] string_ The string to iterate. Must be a pointer to string +** @param[in,out] startCharacterPos_ Here give an uint32_t which will be the character position from which to start the iteration. In each iteration this will hold the character index. If the given position is out of bounds then the iteration does not happen +** @param[in,out] characterUnicodeValue_ Here pass an uint32_t which in each iteration will hold the unicode code point of the character at position startCharacterPos_ +**/ +#define rfString_Iterate_Start(string_,startCharacterPos_,characterUnicodeValue_) {\ + /* b index sec is the byte index and j the character index*/\ + uint32_t byteIndex_ = 0;uint32_t j_=0;\ + /*iterate until we find the character position requested and its equivalent byte position*/\ + while(j_!=startCharacterPos_)\ + {\ + if( rfUTF8_IsContinuationByte( (string_)->bytes[byteIndex_]) ==false)\ + {\ + j_++;\ + }\ + byteIndex_++;\ + }\ + /*now start the requested iteration*/\ + while( (string_)->bytes[byteIndex_]!='\0')\ + {\ + /*if it's a character*/\ + if( rfUTF8_IsContinuationByte( (string_)->bytes[byteIndex_]) ==false)\ + {/*Give the character value to the user*/\ + characterUnicodeValue_ = rfString_BytePosToCodePoint( (string_),byteIndex_); + +// @memberof RF_String +// @cppignore +// @brief Ends an RF_String/RF_StringX forward iteration scope. +// +// @isinherited{StringX} +// Look at #rfString_Iterate_Start for an example usage +// @param[in,out] startCharacterPos_ Here give the uint32_t given to #rfString_Iterate_Start +#define rfString_Iterate_End(startCharacterPos_) startCharacterPos_++;}byteIndex_++;}} + +//Two macros to accomplish iteration of an RF_String from any given character going backwards. This macro should be used with its end pair. +// We take advantage of the fact that an RF_String is always guaranteed to contain a valid UTF-8 sequence and thus no checks are performed. + +/** +** @memberof RF_String +** @cppignore +** @brief Starts an RF_String backward iteration scope. +** +** @isinherited{StringX} +** Use this macro to iterate every character inside an RF_String or RF_StringX going backwards\n +** Must be used with its pair macro #rfString_IterateB_End.\n +** +** As an example consider this code that iterates every character of a string from the start to finish +** @code +** uint32_t charValue; +** RF_String foo;rfString_Init(&foo,"I am a String"); +** uint32_t i = rfString_Length(&foo); +** rfString_IterateB_Start(&foo,i,charValue) +** //for every character in the string,let's print it +** printf("Character at index %d is %c\n",i,charValue); +** rfString_IterateB_End(i) +** @endcode +** @param[in] string_ The string to iterate. Must be a pointer to string +** @param[in,out] characterPos_ Here give an uint32_t which will be the character position from which to start the iteration. In each iteration this will hold the character index. If the given position is out of bounds then the iteration does not happen +** @param[in,out] characterUnicodeValue_ Here pass an uint32_t which in each iteration will hold the unicode code point of the character at position characterPos_ +**/ +#define rfString_IterateB_Start(string_,characterPos_,characterUnicodeValue_) {\ + /* b index is the byte index and j the character index*/\ + uint32_t b_index_ = 0;uint32_t j_=0;\ + /* c index sec is another signed copy of the character index (and is int64_t so that it can cater for any situation). Reason is cause going backwards we gotta have -1 too */\ + int64_t c_index_ = characterPos_;\ + /*iterate until we find the character position requested and its equivalent byte position*/\ + while(j_!=characterPos_)\ + {\ + if( rfUTF8_IsContinuationByte( (string_)->bytes[b_index_]) ==false)\ + {\ + j_++;\ + }\ + b_index_++;\ + }\ + /*now start the requested iteration - notice that the end condition is to reach the first character position*/\ + while(c_index_!=-1)\ + {\ + /*if it's a character*/\ + if( rfUTF8_IsContinuationByte( (string_)->bytes[b_index_]) ==false)\ + {/*Give the character value to the user*/\ + characterUnicodeValue_ = rfString_BytePosToCodePoint( (string_),b_index_); + +// @memberof RF_String +// @cppignore +// @brief Ends an RF_String/RF_StringX backward iteration scope. +// +// @isinherited{StringX} +// Look at #rfString_IterateB_Start for an example usage +// @param[in,out] characterPos_ Here give the uint32_t given to #rfString_IterateB_Start +#define rfString_IterateB_End(characterPos_) c_index_-- ;characterPos_--;}b_index_--;}} + +// @memberof RF_String +// @brief Finds the length of the string in characters. +// +// @isinherited{StringX} +// @param s The string whose number of characters to find. @inhtype{String,StringX} +// @return Returns the length of the sting in characters, not including the null termintion character +i_DECLIMEX_ uint32_t rfString_Length(void * s); + +// @memberof RF_String +// @brief Retrieves the unicode code point of the parameter character. +// +// @isinherited{StringX} +// If the character position is out of bounds RF_STRING_INDEX_OUT_OF_BOUNDS is returned. +// @param thisstr The string whose character code point we need. @inhtype{String,StringX} +// @param c The character index whose unicode code point to return. Must be a positive (including zero) integer. +// @return Returns the code point as an uint32_t or the value RF_STRING_INDEX_OUT_OF_BOUNDS if the requested character index is out of bounds +i_DECLIMEX_ uint32_t rfString_GetChar(void* thisstr,uint32_t c); + +// @internal +// @memberof RF_String +// @cppignore +// @brief Retrieves the unicode code point of the parameter bytepos of the string. +// +// @isinherited{StringX} +// This is an internal function, there is no need to use it. The reason it is exposed here is that it is utilized in the iteration macros. +// @warning DO NOT use this function unless you know what you are doing +// @param thisstr The string whose byte position code point we need. @inhtype{String,StringX} +// @param bytepos The byte position of the string from where to get the code point. +// @warning If this is out of bounds then nothing can detect it and at best it will cause a SEG FAULT. +// Moreover no check to see if this is not a continutation byte is made. All the checks must have been made before calling the function. +// @return Returns the code point of the byte position as an uint32_t +// @endinternal +i_DECLIMEX_ uint32_t rfString_BytePosToCodePoint(void* thisstr,uint32_t bytepos); + +// @internal +// @memberof RF_String +// @cppignore +// @brief Retrieves character position of a byte position +// +// @isinherited{StringX} +// This is an internal function, there is no need to use it. It attempts to retrieve character position from a byte position. If the byte +// position is a continutation byte and does not constitute the start of a character then depending on the option the function will find +// either the next character or the previous character position from this byte position +// +// @warning DO NOT use this function unless you know what you are doing +// @param thisstr The string whose byte position code point we need. @inhtype{String,StringX} +// @param bytepos The byte position of the string from where to get the character position +// @param before A boolean flag denoting the behaviour in case this byte position is a continutation byte. If @c before is true then +// the function will retrieve the first character position before the byte. If it is false, it will retrieve the first character position +// after the continuation byte. +// @endinternal +i_DECLIMEX_ uint32_t rfString_BytePosToCharPos(void* thisstr,uint32_t bytepos,char before); + +// @memberof RF_String +// @opcmpeq +// @brief Compares two Strings and returns true if they are equal and false otherwise +// +// @isinherited{StringX} +// A macro comparing two String and returning true if they are equal and false otherwise. Use it to compare ONLY Strings here not string literals (c strings) +// If you need to compare a String with a string literal (c string) use #rfString_Equal_s +// @lmsFunction +// @param s1 The first string to compare @inhtype{String,StringX} @tmpSTR +// @param s2 The second string to compare @inhtype{String,StringX} @tmpSTR +// @return True in case the strings are equal and false otherwise +#if defined(RF_IAMHERE_FOR_DOXYGEN) +i_DECLIMEX_ char rfString_Equal(void* s1,void* s2); +#else +i_DECLIMEX_ char i_rfString_Equal(void* s1,void* s2); +#define rfString_Equal(i_STRING1_,i_STRING2_) i_rfLMSX_WRAP2(char,i_rfString_Equal,i_STRING1_,i_STRING2_) +#endif + + +// @memberof RF_String +// @brief Finds if a substring exists inside another string. +// +// @isinherited{StringX} +// Finds the existence of String sstr inside this string with the given options. You have the +// option to either match case or perform a case-insensitive search. In addition you can search +// for the exact string and not it just being a part of another string. +// @lmsFunction +// @param thisstr This string we want to search in @inhtype{String,StringX} +// @param sstr The substring string we want to search for @inhtype{String,StringX} @tmpSTR +// @param options \rfoptional{0}. Bitflag options denoting some options for the search.Can have values: +// + @c RF_CASE_IGNORE: If you want the found substring to ignore the case and returns success for any occurence of the string in any case. +// Default search option is to @b match the case. For now this works only for characters of the english language. +// + @c RF_MATCH_WORD: If you want the found substring to be exact. For example an exact search for @e "HELLO" in the string +// @e "HELLOWORLD" would return a failure. Default search is to return any found substring. +// @return Returns the character position of the found substring or RF_FAILURE for not found +#if defined(RF_IAMHERE_FOR_DOXYGEN) +i_DECLIMEX_ int32_t rfString_Find(const void* thisstr,const void* sstr,const char options); +#else +i_DECLIMEX_ int32_t i_rfString_Find(const void* thisstr,const void* sstr,const char* options); + #ifndef RF_OPTION_DEFAULT_ARGUMENTS + #define rfString_Find(i_THISSTR_,i_SEARCHSTR_,i_OPTIONS_) i_rfLMS_WRAP3(int32_t,i_rfString_Find,i_THISSTR_,i_SEARCHSTR_,i_RFI8_(i_OPTIONS_)) + #else + #define rfString_Find(...) RF_SELECT_FUNC_IF_NARGGT(i_NPSELECT_RF_STRING_FIND,3,__VA_ARGS__) + #define i_NPSELECT_RF_STRING_FIND1(...) RF_COMPILE_ERROR("message \"Ileggal Arguments Number: Function rfString_Find() accepts from 2 to 3 arguments\"") + #define i_NPSELECT_RF_STRING_FIND0(...) RF_SELECT_FUNC(i_SELECT_RF_STRING_FIND,__VA_ARGS__) + #define i_SELECT_RF_STRING_FIND2(i_THISSTR_,i_SEARCHSTR_) i_rfLMS_WRAP3(int32_t,i_rfString_Find,i_THISSTR_,i_SEARCHSTR_,i_RFI8_(0)) + #define i_SELECT_RF_STRING_FIND3(i_THISSTR_,i_SEARCHSTR_,i_OPTIONS_) i_rfLMS_WRAP3(int32_t,i_rfString_Find,i_THISSTR_,i_SEARCHSTR_,i_RFI8_(i_OPTIONS_)) + #define i_SELECT_RF_STRING_FIND1(...) RF_COMPILE_ERROR("message \"Illegal Arguments Number: Function rfString_Find() accepts from 2 to 3 arguments\"") + #define i_SELECT_RF_STRING_FIND0(...) RF_COMPILE_ERROR("message \"Illegal Arguments Number: Function rfString_Find() accepts from 2 to 3 arguments\"") + #endif +#endif + + +// @memberof RF_String +// @brief Returns the integer value of a String +// +// @isinherited{StringX} +// The parameter string must contains only numbers. If it contains anything else the function fails. +// @param thisstr The string whose integer value to return. @inhtype{String,StringX} +// @param[out] v A refence to an integer that will return the float value +// @return Returns true in case of succesfull conversion or false if no integer was represented by the string +i_DECLIMEX_ char rfString_ToInt(void* thisstr,int32_t* v); + +// @memberof RF_String +// @brief Returns the double value of a String +// +// @isinherited{StringX} +// The parameter string must contain only a number. If it contains anything else the function fails. +// @param thisstr The string whose floating point value to return. @inhtype{String,StringX} +// @param[out] f A refence to a double that will return the floating point number value +// @return Returns RF_SUCCESS in case of succesfull conversion or error if there was failure. Possible errors are: +// + @c RE_STRING_TOFLOAT: There was a conversion error. The string probably does not represent a float +// + @c RE_STRING_TOFLOAT_RANGE: The represented floating point number is of a range bigger than what can be +// represented by the system +// + @c RE_STRING_TOFLOAT_UNDERFLOW: Representing the string's floating point number in a double would cause underflow +i_DECLIMEX_ int rfString_ToDouble(void* thisstr,double* f); + +// @memberof RF_String +// @brief Returns a cstring version of the string +// +// @isinherited{StringX} +// Remember that this is just a pointer to the string data. It can't be modified. memcpy it if you need a copy of it. +// @param str The string whose cstring to return. @inhtype{String,StringX} +// @return Returns a c string version of the string +i_DECLIMEX_ const char* rfString_ToCstr(const void* str); + + +// @memberof RF_String +// @cppignore +// @brief Creates and returns an allocated copy of the given string +// +// @isinherited{StringX} +// @note The Returned Substring needs to be freed by the user. BEWARE when assigning to a string using this function since if any previous string exists there IS NOT getting freed. You have to free it explicitly +// @param src The string to copy from. @inhtype{String,StringX} +// @return Returns a string copied from the previous one or null if the original string was null +i_DECLIMEX_ RF_String* rfString_Copy_OUT(void* src); +// @memberof RF_String +// @cppignore +// @brief Copies all the contents of a string to another +// +// @isinherited{StringX} +// @param dst The string to copy in. +// @param src The string to copy from. @inhtype{String,StringX} +// If the value is bigger than the maximum number of characters then still all characters are copied. +i_DECLIMEX_ void rfString_Copy_IN(RF_String* dst,void* src); +// @memberof RF_String +// @brief Copies a certain number of characters from a string +// +// @isinherited{StringX} +// Copies @c n characters from @c src String into the destination @c dst string. +// @param dst The string to copy in +// @param src The string to copy from. @inhtype{String,StringX} +// @param n The number of characters to copy from the @c src string +// If the value is bigger than the maximum number of characters then still all characters are copied. +i_DECLIMEX_ void rfString_Copy_chars(RF_String* dst,void* src,uint32_t n); + + +// @memberof RF_String +// @brief Applies a limited version of sscanf after the specified substring +// +// @isinherited{StringX} +// @lmsFunction +// @param thisstr The current string. @inhtype{String,StringX} +// @param afterstr The substring after which to apply sscanf. @inhtype{String,StringX} @tmpSTR +// @param format The tokens parameter which give the format of scanf +// @param var A void* to pass in any variable we need to get a value +// @return Returns true if a value was read and false otherwise, substring not being found in the string or sscanf unable to read into the variable +#if defined(RF_IAMHERE_FOR_DOXYGEN) + i_DECLIMEX_ char rfString_ScanfAfter(void* thisstr,void* afterstr,const char* format,void* var); +#else + i_DECLIMEX_ char i_rfString_ScanfAfter(void* thisstr,void* afterstr,const char* format,void* var); + #define rfString_ScanfAfter(i_THISSTR_,i_AFTERSTR_,i_FORMAT_,i_VAR_) i_rfLMSX_WRAP4(char,i_rfString_ScanfAfter,i_THISSTR_,i_AFTERSTR_,i_FORMAT_,i_VAR_) +#endif + +// @memberof RF_String +// @brief Counts how many times a substring occurs inside the string. +// +// @isinherited{StringX} +// @lmsFunction +// @param thisstr The string inside which to count. @inhtype{String,StringX} +// @param sstr The substring for which to search. @inhtype{String,StringX} @tmpSTR +// @param options \rfoptional{0}. Bitflag options denoting some options for the search. Give 0 for the defaults.Can have values: +// + @c RF_CASE_IGNORE: If you want the found substring to ignore the case and returns success for any occurence of the string in any case. +// Default search option is to @b match the case. For now this works only for characters of the english language. +// + @c RF_MATCH_WORD: If you want the found substring to be exact. For example an exact search for @e "HELLO" in the string +// @e "HELLOWORLD" would return a failure. Default search is to return any found substring. +// @return Returns the number of times cstr exists inside the string (0 is returned in case it's not found at all +#if defined(RF_IAMHERE_FOR_DOXYGEN) +i_DECLIMEX_ int32_t rfString_Count(void* thisstr,void* sstr,const char options); +#else +i_DECLIMEX_ int32_t i_rfString_Count(void* thisstr,void* sstr,const char* options); + #ifdef RF_OPTION_DEFAULT_ARGUMENTS + #define rfString_Count(...) RF_SELECT_FUNC_IF_NARGGT(i_NPSELECT_RF_STRING_COUNT,3,__VA_ARGS__) + #define i_NPSELECT_RF_STRING_COUNT1(...) RF_COMPILE_ERROR("message \"Ileggal Arguments Number: Function rfString_Count() accepts from 2 to 3 arguments\"") + #define i_NPSELECT_RF_STRING_COUNT0(...) RF_SELECT_FUNC(i_SELECT_RF_STRING_COUNT,__VA_ARGS__) + #define i_SELECT_RF_STRING_COUNT2(i_THISSTR_,i_SEARCHSTR_) i_rfLMSX_WRAP3(int32_t,i_rfString_Count,i_THISSTR_,i_SEARCHSTR_,i_RFI8_(0)) + #define i_SELECT_RF_STRING_COUNT3(i_THISSTR_,i_SEARCHSTR_,i_OPTIONS_) i_rfLMS_WRAP3(int32_t,i_rfString_Count,i_THISSTR_,i_SEARCHSTR_,i_RFI8_(i_OPTIONS_)) + #define i_SELECT_RF_STRING_COUNT1(...) RF_COMPILE_ERROR("message \"Ileggal Arguments Number: Function rfString_Count() accepts from 2 to 3 arguments\"") + #define i_SELECT_RF_STRING_COUNT0(...) RF_COMPILE_ERROR("message \"Ileggal Arguments Number: Function rfString_Count() accepts from 2 to 3 arguments\"") + #else + #define rfString_Count(i_THISSTR_,i_SEARCHSTR_,i_OPTIONS_) i_rfLMSX_WRAP3(int32_t,i_rfString_Count,i_THISSTR_,i_SEARCHSTR_,i_RFI8_(i_OPTIONS_)) + #endif +#endif + + +// @memberof RF_String +// @brief Tokenizes the given string +// +// @isinherited{StringX} +// Separates it into @c tokensN depending on how many substrings can be created from the @c sep separatior and stores them +// into the Array of RF_String* that should be passed to the function. The array gets initialized inside the function and +// has to be freed explicitly later by thg user. Also each String inside the array has to be Deinitialized too. +// Here is an example usage: +// @snippet Strings/tokenize.cpp Tokenize_C +// @cppsnippet Tokenize_CPP +// @param[in] thisstr The string to tokenize. @inhtype{String,StringX} +// @param[in] sep A string literal that will be used as a separator to tokenize the given string +// @param[out] tokensN The number of tokens that got created +// @param[out] tokens Pass a pointer to an array of RF_Strings. @keepptr +// @return Returns true in success and false in case the the separating character has not been found +// @internal @cppcode +// char String::Tokenize(char* sep,uint32_t* tokensN, String*** tokens) +// { +// RF_String* t; +// uint32_t i; +// if(rfString_Tokenize(this->i_StringCHandle,sep,tokensN,&t)==false) +// return false; +// +// *tokens = (String**) malloc(sizeof(String*)* (*tokensN)); +// for(i=0;i<(*tokensN);i++) +// { +// (*tokens)[i] = new String((RF_String*)&t[i]); +// } +// return true; +// } +// @endcpp @endinternal +i_DECLIMEX_ char rfString_Tokenize(void* thisstr,char* sep,uint32_t* tokensN,RF_String** tokens); + + +// @memberof RF_String +// @brief Initializes the first substring, between two given strings +// +// @isinherited{StringX} +// Initializes the given string as the first substring existing between the left and right parameter substrings +// @lmsFunction +// @note The Returned Substring needs to be deinitialized by the user. +// @param thisstr This current string. @inhtype{String,StringX} +// @param[in] lstr The left substring that will define the new substring. @inhtype{String,StringX} @tmpSTR +// @param[in] rstr The right substring that will define the new substring. @inhtype{String,StringX} @tmpSTR +// @param[out] result The resulting substring. +// @param options \rfoptional{0} Bitflag options denoting the method with which to search for the substring literals inside the string. Give 0 for the defaults. +// Can have values: +// + @c RF_CASE_IGNORE: If you want to search for any occurence of the substring disregarding CAPS or not. +// Default search option is to @b match the case. For now this works only for characters of the english language. +// + @c RF_MATCH_WORD: If you to find only exact matches of the substring. For example an exact search for @e "HELLO" in the string +// @e "HELLOWORLD" would find nothing. Default is with this flag off. +// @return Returns true if the substring is found and initialized and false otherwise +#if defined(RF_IAMHERE_FOR_DOXYGEN) +i_DECLIMEX_ char rfString_Between(void* thisstr,void* lstr,void* rstr,RF_String* result,const char options); +#else +i_DECLIMEX_ char i_rfString_Between(void* thisstr,void* lstr,void* rstr,RF_String* result,const char* options); + #ifdef RF_OPTION_DEFAULT_ARGUMENTS + #define rfString_Between(...) RF_SELECT_FUNC_IF_NARGGT(i_NPSELECT_RF_STRING_BETWEEN,5,__VA_ARGS__) + #define i_NPSELECT_RF_STRING_BETWEEN1(...) RF_COMPILE_ERROR("message \"Ileggal Arguments Number: Function rfString_Between() accepts from 4 to 5 arguments\"") + #define i_NPSELECT_RF_STRING_BETWEEN0(...) RF_SELECT_FUNC(i_SELECT_RF_STRING_BETWEEN,__VA_ARGS__) + #define i_SELECT_RF_STRING_BETWEEN4(i_THISSTR_,i_LEFTSTR_,i_RIGHTSTR_,i_RESULT_) \ + i_rfLMSX_WRAP5(char,i_rfString_Between,i_THISSTR_,i_LEFTSTR_,i_RIGHTSTR_,i_RESULT_,i_RFI8_(0)) + #define i_SELECT_RF_STRING_BETWEEN5(i_THISSTR_,i_LEFTSTR_,i_RIGHTSTR_,i_RESULT_,i_OPTIONS_) \ + i_rfLMSX_WRAP5(char,i_rfString_Between,i_THISSTR_,i_LEFTSTR_,i_RIGHTSTR_,i_RESULT_,i_RFI8_(i_OPTIONS_)) + #define i_SELECT_RF_STRING_BETWEEN3(...) RF_COMPILE_ERROR("message \"Illegal Arguments Number: Function rfString_Between() accepts from 4 to 5 arguments\"") + #define i_SELECT_RF_STRING_BETWEEN2(...) RF_COMPILE_ERROR("message \"Illegal Arguments Number: Function rfString_Between() accepts from 4 to 5 arguments\"") + #define i_SELECT_RF_STRING_BETWEEN1(...) RF_COMPILE_ERROR("message \"Illegal Arguments Number: Function rfString_Between() accepts from 4 to 5 arguments\"") + #define i_SELECT_RF_STRING_BETWEEN0(...) RF_COMPILE_ERROR("message \"Illegal Arguments Number: Function rfString_Between() accepts from 4 to 5 arguments\"") + #else + #define rfString_Between(i_THISSTR_,i_LEFTSTR_,i_RIGHTSTR_,i_RESULT_,i_OPTIONS_) \ + i_rfLMSX_WRAP5(char,i_rfString_Between,i_THISSTR_,i_LEFTSTR_,i_RIGHTSTR_,i_RESULT_,i_RFI8_(i_OPTIONS_)) + #endif +#endif + + +// @memberof RF_String +// @brief Initializes the given string as the substring from the start until any of the given Strings are found +// +// @isinherited{StringX} +// The parameters that have to be given as variable argument must be of type RF_String* or RF_StringX* or even +// string initialized with the temporary string macro +// @rfNoDefArgsWarn1 +// @warning if the library has been compiled with @c DEFAULT_ARGUMENTS off then arguments @c options and @c parN are actually pointers +// to @c char and @c unsigned char respectively +// @lmsFunction +// @param thisstr The string to operate in. @inhtype{String,StringX} +// @param result The resulting substring. +// @param options Bitflag options denoting the method with which to search for the substring literals inside the string. Give 0 for the defaults. +// Can have values: +// + @c RF_CASE_IGNORE: If you want to search for any occurence of the substring disregarding CAPS or not. +// Default search option is to @b match the case. For now this works only for characters of the english language. +// + @c RF_MATCH_WORD: If you to find only exact matches of the substring. For example an exact search for @e "HELLO" in the string +// @e "HELLOWORLD" would find nothing. Default is with this flag off. +// @param parN The number of strings to search for +// @param ... The strings to search for. @inhtype{String,StringX} @tmpSTR +// @extraVarArgLim +// @return Returns true if the substring was initialized and false if none of the parameters were found or an invalid UTF-8 sequence was given. In the latter case an error is also logged. +#ifdef RF_IAMHERE_FOR_DOXYGEN +i_DECLIMEX_ char rfString_Beforev(void* thisstr,RF_String* result,const char options,const unsigned char parN, ...); +#endif +#ifdef RF_OPTION_DEFAULT_ARGUMENTS + i_DECLIMEX_ char i_rfString_Beforev(void* thisstr,RF_String* result,const char* options,const unsigned char* parN, ...); + #define rfString_Beforev(...) RF_SELECT_FUNC_IF_NARGGT(i_NPSELECT_RF_STRING_BEFOREV,4,__VA_ARGS__) + #define i_NPSELECT_RF_STRING_BEFOREV1(...) RF_SELECT_FUNC_IF_NARGGT2(i_LIMSELECT_RF_STRING_BEFOREV,18,__VA_ARGS__) + #define i_NPSELECT_RF_STRING_BEFOREV0(...) RF_COMPILE_ERROR("message \"Illegal Arguments Number: Function rfString_Beforev() needs to receive more than 4 arguments\"") + #define i_LIMSELECT_RF_STRING_BEFOREV1(...) RF_COMPILE_ERROR("message \"Extra Arguments Limit Reached: Function rfString_Beforev() received more extra arguments than the limit permits\"") + #define i_LIMSELECT_RF_STRING_BEFOREV0(...) RF_SELECT_FUNC(i_SELECT_RF_STRING_BEFOREV,__VA_ARGS__) + #define i_SELECT_RF_STRING_BEFOREV5(i_ARG1_,i_ARG2_,i_ARG3_,i_ARG4_,...) \ + i_rfLMSX_WRAP5(char,i_rfString_Beforev,i_ARG1_,i_ARG2_,i_RFI8_(i_ARG3_),i_RFUI8_(i_ARG4_),__VA_ARGS__) + #define i_SELECT_RF_STRING_BEFOREV6(i_ARG1_,i_ARG2_,i_ARG3_,i_ARG4_,...) i_rfLMSX_WRAP6(char,i_rfString_Beforev,i_ARG1_,i_ARG2_,i_RFI8_(i_ARG3_),i_RFUI8_(i_ARG4_),__VA_ARGS__) + #define i_SELECT_RF_STRING_BEFOREV7(i_ARG1_,i_ARG2_,i_ARG3_,i_ARG4_,...) i_rfLMSX_WRAP7(char,i_rfString_Beforev,i_ARG1_,i_ARG2_,i_RFI8_(i_ARG3_),i_RFUI8_(i_ARG4_),__VA_ARGS__) + #define i_SELECT_RF_STRING_BEFOREV8(i_ARG1_,i_ARG2_,i_ARG3_,i_ARG4_,...) i_rfLMSX_WRAP8(char,i_rfString_Beforev,i_ARG1_,i_ARG2_,i_RFI8_(i_ARG3_),i_RFUI8_(i_ARG4_),__VA_ARGS__) + #define i_SELECT_RF_STRING_BEFOREV9(i_ARG1_,i_ARG2_,i_ARG3_,i_ARG4_,...) i_rfLMSX_WRAP9(char,i_rfString_Beforev,i_ARG1_,i_ARG2_,i_RFI8_(i_ARG3_),i_RFUI8_(i_ARG4_),__VA_ARGS__) + #define i_SELECT_RF_STRING_BEFOREV10(i_ARG1_,i_ARG2_,i_ARG3_,i_ARG4_,...) i_rfLMSX_WRAP10(char,i_rfString_Beforev,i_ARG1_,i_ARG2_,i_RFI8_(i_ARG3_),i_RFUI8_(i_ARG4_),__VA_ARGS__) + #define i_SELECT_RF_STRING_BEFOREV11(i_ARG1_,i_ARG2_,i_ARG3_,i_ARG4_,...) i_rfLMSX_WRAP11(char,i_rfString_Beforev,i_ARG1_,i_ARG2_,i_RFI8_(i_ARG3_),i_RFUI8_(i_ARG4_),__VA_ARGS__) + #define i_SELECT_RF_STRING_BEFOREV12(i_ARG1_,i_ARG2_,i_ARG3_,i_ARG4_,...) i_rfLMSX_WRAP12(char,i_rfString_Beforev,i_ARG1_,i_ARG2_,i_RFI8_(i_ARG3_),i_RFUI8_(i_ARG4_),__VA_ARGS__) + #define i_SELECT_RF_STRING_BEFOREV13(i_ARG1_,i_ARG2_,i_ARG3_,i_ARG4_,...) i_rfLMSX_WRAP13(char,i_rfString_Beforev,i_ARG1_,i_ARG2_,i_RFI8_(i_ARG3_),i_RFUI8_(i_ARG4_),__VA_ARGS__) + #define i_SELECT_RF_STRING_BEFOREV14(i_ARG1_,i_ARG2_,i_ARG3_,i_ARG4_,...) i_rfLMSX_WRAP14(char,i_rfString_Beforev,i_ARG1_,i_ARG2_,i_RFI8_(i_ARG3_),i_RFUI8_(i_ARG4_),__VA_ARGS__) + #define i_SELECT_RF_STRING_BEFOREV15(i_ARG1_,i_ARG2_,i_ARG3_,i_ARG4_,...) i_rfLMSX_WRAP15(char,i_rfString_Beforev,i_ARG1_,i_ARG2_,i_RFI8_(i_ARG3_),i_RFUI8_(i_ARG4_),__VA_ARGS__) + #define i_SELECT_RF_STRING_BEFOREV16(i_ARG1_,i_ARG2_,i_ARG3_,i_ARG4_,...) i_rfLMSX_WRAP16(char,i_rfString_Beforev,i_ARG1_,i_ARG2_,i_RFI8_(i_ARG3_),i_RFUI8_(i_ARG4_),__VA_ARGS__) + #define i_SELECT_RF_STRING_BEFOREV17(i_ARG1_,i_ARG2_,i_ARG3_,i_ARG4_,...) i_rfLMSX_WRAP17(char,i_rfString_Beforev,i_ARG1_,i_ARG2_,i_RFI8_(i_ARG3_),i_RFUI8_(i_ARG4_),__VA_ARGS__) + #define i_SELECT_RF_STRING_BEFOREV18(i_ARG1_,i_ARG2_,i_ARG3_,i_ARG4_,...) i_rfLMSX_WRAP18(char,i_rfString_Beforev,i_ARG1_,i_ARG2_,i_RFI8_(i_ARG3_),i_RFUI8_(i_ARG4_),__VA_ARGS__) +#else + i_DECLIMEX_ char rfString_Beforev(void* thisstr,RF_String* result,const char* options,const unsigned char* parN, ...); +#endif + +// @memberof RF_String +// @brief Initializes the given string as the substring from the start until the given string is found +// +// @isinherited{StringX} +// @lmsFunction +// @param thisstr The string to operate in. @inhtype{String,StringX} +// @param sstr The substring that we want to find inside the string @inhtype{String,StringX} @tmpSTR +// @param result The resulting substring. +// @param options \rfoptional{0} Bitflag options denoting the method with which to search for the substring literals inside the string. Give 0 for the defaults. +// Can have values: +// + @c RF_CASE_IGNORE: If you want to search for any occurence of the substring disregarding CAPS or not. +// Default search option is to @b match the case. For now this works only for characters of the english language. +// + @c RF_MATCH_WORD: If you to find only exact matches of the substring. For example an exact search for @e "HELLO" in the string +// @e "HELLOWORLD" would find nothing. Default is with this flag off. +// @return Returns true if the substring was initialized and false if none of the parameters were found or an invalid UTF-8 sequence was given. In the latter case an error is also logged. +#if defined(RF_IAMHERE_FOR_DOXYGEN) +i_DECLIMEX_ char rfString_Before(void* thisstr,void* sstr,RF_String* result,const char options); +#else +i_DECLIMEX_ char i_rfString_Before(void* thisstr,void* sstr,RF_String* result,const char* options); + #ifdef RF_OPTION_DEFAULT_ARGUMENTS + #define rfString_Before(...) RF_SELECT_FUNC_IF_NARGGT(i_NPSELECT_RF_STRING_BEFORE,4,__VA_ARGS__) + #define i_NPSELECT_RF_STRING_BEFORE1(...) RF_COMPILE_ERROR("message \"Ileggal Arguments Number: Function rfString_Before() accepts from 3 to 4 arguments\"") + #define i_NPSELECT_RF_STRING_BEFORE0(...) RF_SELECT_FUNC(i_SELECT_RF_STRING_BEFORE,__VA_ARGS__) + #define i_SELECT_RF_STRING_BEFORE3(i_THISSTR_,i_SEARCHSTR_,i_RESULT_) i_rfLMSX_WRAP4(char,i_rfString_Before,i_THISSTR_,i_SEARCHSTR_,i_RESULT_,i_RFI8_(0)) + #define i_SELECT_RF_STRING_BEFORE4(i_THISSTR_,i_SEARCHSTR_,i_RESULT_,i_OPTIONS_) i_rfLMSX_WRAP4(char,i_rfString_Before,i_THISSTR_,i_SEARCHSTR_,i_RESULT_,i_RFI8_(i_OPTIONS_)) + #define i_SELECT_RF_STRING_BEFORE2(...) RF_COMPILE_ERROR("message \"Ileggal Arguments Number: Function rfString_Before() accepts from 3 to 4 arguments\"") + #define i_SELECT_RF_STRING_BEFORE1(...) RF_COMPILE_ERROR("message \"Ileggal Arguments Number: Function rfString_Before() accepts from 3 to 4 arguments\"") + #define i_SELECT_RF_STRING_BEFORE0(...) RF_COMPILE_ERROR("message \"Ileggal Arguments Number: Function rfString_Before() accepts from 3 to 4 arguments\"") + #else + #define rfString_Before(i_THISSTR_,i_SEARCHSTR_,i_RESULT_,i_OPTIONS_) i_rfLMSX_WRAP4(char,i_rfString_Before,i_THISSTR_,i_SEARCHSTR_,i_RESULT_,i_RFI8_(i_OPTIONS_)) + #endif +#endif + +// @memberof RF_String +// @brief Initialize a string after a given substring +// +// @isinherited{StringX} +// Initializes the given String with the substring located after (and not including) the after substring inside the parameter string. If the substring is not located the function returns false. +// @note The given String needs to be deinitialized by the user +// @lmsFunction +// @param[in] thisstr The parameter string from which the substring will be formed. @inhtype{String,StringX} +// @param[in] after The substring to search for inside the parameter string. @inhtype{String,StringX} @tmpSTR +// @param[out] out Pass a reference to a String inside which the substring of the original string after the @c after substring will be placed +// @param options \rfoptional{0} Bitflag options denoting the method with which to search for the substring literals inside the string. Give 0 for the defaults. +// Can have values: +// + @c RF_CASE_IGNORE: If you want to search for any occurence of the substring disregarding CAPS or not. +// Default search option is to @b match the case. For now this works only for characters of the english language. +// + @c RF_MATCH_WORD: If you to find only exact matches of the substring. For example an exact search for @e "HELLO" in the string +// @e "HELLOWORLD" would find nothing. Default is with this flag off. +// @return Returns true for success and false if the substring is not found in the parameter string. +#if defined(RF_IAMHERE_FOR_DOXYGEN) +i_DECLIMEX_ char rfString_After(void* thisstr,void* after,RF_String* out,const char options); +#else +i_DECLIMEX_ char i_rfString_After(void* thisstr,void* after,RF_String* out,const char* options); + #ifdef RF_OPTION_DEFAULT_ARGUMENTS + #define rfString_After(...) RF_SELECT_FUNC_IF_NARGGT(i_NPSELECT_RF_STRING_AFTER,4,__VA_ARGS__) + #define i_NPSELECT_RF_STRING_AFTER1(...) RF_COMPILE_ERROR("message \"Ileggal Arguments Number: Function rfString_After() accepts from 3 to 4 arguments\"") + #define i_NPSELECT_RF_STRING_AFTER0(...) RF_SELECT_FUNC(i_SELECT_RF_STRING_AFTER,__VA_ARGS__) + #define i_SELECT_RF_STRING_AFTER3(i_THISSTR_,i_AFTERSTR_,i_OUTSTR_) i_rfLMSX_WRAP4(char,i_rfString_After,i_THISSTR_,i_AFTERSTR_,i_OUTSTR_,i_RFI8_(0)) + #define i_SELECT_RF_STRING_AFTER4(i_THISSTR_,i_AFTERSTR_,i_OUTSTR_,i_OPTIONS_) i_rfLMSX_WRAP4(char,i_rfString_After,i_THISSTR_,i_AFTERSTR_,i_OUTSTR_,i_RFI8_(i_OPTIONS_)) + #define i_SELECT_RF_STRING_AFTER2(...) RF_COMPILE_ERROR("message \"Ileggal Arguments Number: Function rfString_After() accepts from 3 to 4 arguments\"") + #define i_SELECT_RF_STRING_AFTER1(...) RF_COMPILE_ERROR("message \"Ileggal Arguments Number: Function rfString_After() accepts from 3 to 4 arguments\"") + #define i_SELECT_RF_STRING_AFTER0(...) RF_COMPILE_ERROR("message \"Ileggal Arguments Number: Function rfString_After() accepts from 3 to 4 arguments\"") + #else + #define rfString_After(i_THISSTR_,i_AFTERSTR_,i_OUTSTR_,i_OPTIONS_) i_rfLMSX_WRAP4(char,i_rfString_After,i_THISSTR_,i_AFTERSTR_,i_OUTSTR_,i_RFI8_(i_OPTIONS_)) + #endif +#endif + +// @memberof RF_String +// @brief Initialize a string after the first of the given substrings found +// +// @isinherited{StringX} +// Initializes the given String with the substring located after (and not including) the after substring inside the parameter string. If the substring is not located the function returns false. +// The parameters that have to be given as variable argument must be of type RF_String* or RF_StringX* or even +// string initializes with the temporary string macro +// @rfNoDefArgsWarn1 +// @warning if the library has been compiled with @c DEFAULT_ARGUMENTS off then arguments @c options and @c parN are actually pointers +// to @c char and @c unsigned char respectively +// @lmsFunction +// @param[in] thisstr The parameter string from which the substring will be formed. @inhtype{String,StringX} +// @param[out] out Pass a reference to a String inside which the substring of the original string +// after the found substring will be placed. +// @param options \rfoptional{0} Bitflag options denoting the method with which to search for the substring literals inside the string. Give 0 for the defaults. +// Can have values: +// + @c RF_CASE_IGNORE: If you want to search for any occurence of the substring disregarding CAPS or not. +// Default search option is to @b match the case. For now this works only for characters of the english language. +// + @c RF_MATCH_WORD: If you to find only exact matches of the substring. For example an exact search for @e "HELLO" in the string +// @e "HELLOWORLD" would find nothing. Default is with this flag off. +// @param parN The number of substrings to search for. +// @param ... The substrings to search for. @inhtype{String,StringX} @tmpSTR +// @extraVarArgLim +// @return Returns true for success and false if the substring is not found in the parameter string. +#ifdef RF_IAMHERE_FOR_DOXYGEN +i_DECLIMEX_ char rfString_Afterv(void* thisstr,RF_String* out,const char options,const unsigned char parN,...); +#endif +#ifdef RF_OPTION_DEFAULT_ARGUMENTS +i_DECLIMEX_ char i_rfString_Afterv(void* thisstr,RF_String* out,const char* options,const unsigned char* parN,...); + #define rfString_Afterv(...) RF_SELECT_FUNC_IF_NARGGT(i_NPSELECT_RF_STRING_AFTERV,4,__VA_ARGS__) + #define i_NPSELECT_RF_STRING_AFTERV1(...) RF_SELECT_FUNC_IF_NARGGT2(i_LIMSELECT_RF_STRING_AFTERV,18,__VA_ARGS__) + #define i_NPSELECT_RF_STRING_AFTERV0(...) RF_COMPILE_ERROR("message \"Ileggal Arguments Number: Function rfString_Afterv() needs to receive more than 4 arguments\"") + #define i_LIMSELECT_RF_STRING_AFTERV1(...) RF_COMPILE_ERROR("message \"Extra Arguments Limit Reached: Function rfString_Afterv() received more extra arguments than the limit permits\"") + #define i_LIMSELECT_RF_STRING_AFTERV0(...) RF_SELECT_FUNC(i_SELECT_RF_STRING_AFTERV,__VA_ARGS__) + #define i_SELECT_RF_STRING_AFTERV5(i_ARG1_,i_ARG2_,i_ARG3_,i_ARG4_,...) i_rfLMSX_WRAP5(char,i_rfString_Afterv,i_ARG1_,i_ARG2_,i_RFI8_((i_ARG3_),i_RFUI8_(i_ARG4_),__VA_ARGS__) + #define i_SELECT_RF_STRING_AFTERV6(i_ARG1_,i_ARG2_,i_ARG3_,i_ARG4_,...) i_rfLMSX_WRAP6(char,i_rfString_Afterv,i_ARG1_,i_ARG2_,i_RFI8_((i_ARG3_),i_RFUI8_(i_ARG4_),__VA_ARGS__) + #define i_SELECT_RF_STRING_AFTERV7(i_ARG1_,i_ARG2_,i_ARG3_,i_ARG4_,...) i_rfLMSX_WRAP7(char,i_rfString_Afterv,i_ARG1_,i_ARG2_,i_RFI8_((i_ARG3_),i_RFUI8_(i_ARG4_),__VA_ARGS__) + #define i_SELECT_RF_STRING_AFTERV8(i_ARG1_,i_ARG2_,i_ARG3_,i_ARG4_,...) i_rfLMSX_WRAP8(char,i_rfString_Afterv,i_ARG1_,i_ARG2_,i_RFI8_((i_ARG3_),i_RFUI8_(i_ARG4_),__VA_ARGS__) + #define i_SELECT_RF_STRING_AFTERV9(i_ARG1_,i_ARG2_,i_ARG3_,i_ARG4_,...) i_rfLMSX_WRAP9(char,i_rfString_Afterv,i_ARG1_,i_ARG2_,i_RFI8_((i_ARG3_),i_RFUI8_(i_ARG4_),__VA_ARGS__) + #define i_SELECT_RF_STRING_AFTERV10(i_ARG1_,i_ARG2_,i_ARG3_,i_ARG4_,...) i_rfLMSX_WRAP10(char,i_rfString_Afterv,i_ARG1_,i_ARG2_,i_RFI8_((i_ARG3_),i_RFUI8_(i_ARG4_),__VA_ARGS__) + #define i_SELECT_RF_STRING_AFTERV11(i_ARG1_,i_ARG2_,i_ARG3_,i_ARG4_,...) i_rfLMSX_WRAP11(char,i_rfString_Afterv,i_ARG1_,i_ARG2_,i_RFI8_((i_ARG3_),i_RFUI8_(i_ARG4_),__VA_ARGS__) + #define i_SELECT_RF_STRING_AFTERV12(i_ARG1_,i_ARG2_,i_ARG3_,i_ARG4_,...) i_rfLMSX_WRAP12(char,i_rfString_Afterv,i_ARG1_,i_ARG2_,i_RFI8_((i_ARG3_),i_RFUI8_(i_ARG4_),__VA_ARGS__) + #define i_SELECT_RF_STRING_AFTERV13(i_ARG1_,i_ARG2_,i_ARG3_,i_ARG4_,...) i_rfLMSX_WRAP13(char,i_rfString_Afterv,i_ARG1_,i_ARG2_,i_RFI8_((i_ARG3_),i_RFUI8_(i_ARG4_),__VA_ARGS__) + #define i_SELECT_RF_STRING_AFTERV14(i_ARG1_,i_ARG2_,i_ARG3_,i_ARG4_,...) i_rfLMSX_WRAP14(char,i_rfString_Afterv,i_ARG1_,i_ARG2_,i_RFI8_((i_ARG3_),i_RFUI8_(i_ARG4_),__VA_ARGS__) + #define i_SELECT_RF_STRING_AFTERV15(i_ARG1_,i_ARG2_,i_ARG3_,i_ARG4_,...) i_rfLMSX_WRAP15(char,i_rfString_Afterv,i_ARG1_,i_ARG2_,i_RFI8_((i_ARG3_),i_RFUI8_(i_ARG4_),__VA_ARGS__) + #define i_SELECT_RF_STRING_AFTERV16(i_ARG1_,i_ARG2_,i_ARG3_,i_ARG4_,...) i_rfLMSX_WRAP16(char,i_rfString_Afterv,i_ARG1_,i_ARG2_,i_RFI8_((i_ARG3_),i_RFUI8_(i_ARG4_),__VA_ARGS__) + #define i_SELECT_RF_STRING_AFTERV17(i_ARG1_,i_ARG2_,i_ARG3_,i_ARG4_,...) i_rfLMSX_WRAP17(char,i_rfString_Afterv,i_ARG1_,i_ARG2_,i_RFI8_((i_ARG3_),i_RFUI8_(i_ARG4_),__VA_ARGS__) + #define i_SELECT_RF_STRING_AFTERV18(i_ARG1_,i_ARG2_,i_ARG3_,i_ARG4_,...) i_rfLMSX_WRAP18(char,i_rfString_Afterv,i_ARG1_,i_ARG2_,i_RFI8_((i_ARG3_),i_RFUI8_(i_ARG4_),__VA_ARGS__) +#else + char rfString_Afterv(void* thisstr,RF_String* out,const char* options,const unsigned char* parN,...); +#endif + + + +// @} +/*------------------------------------------------------------------------ RF_String manipulation functions-------------------------------------------------------------------------------*/ +// @name String Manipulation +// @{ + +// @memberof RF_String +// @opadd +// @brief Appends a string to this one +// +// @notinherited{StringX} +// @lmsFunction +// @param thisstr The string to append to +// @param other The string to add to this string. @inhtype{String,StringX} @tmpSTR +#if defined(RF_IAMHERE_FOR_DOXYGEN) +i_DECLIMEX_ void rfString_Append(RF_String* thisstr,void* other); +#else +i_DECLIMEX_ void i_rfString_Append(RF_String* thisstr,void* other); +#define rfString_Append(i_THISSTR_,i_OTHERSTR_) i_rfLMS_WRAP2(void,i_rfString_Append,i_THISSTR_,i_OTHERSTR_) +#endif + +// @memberof RF_String +// @opadd +// @brief Appends an integer to the string +// +// @notinherited{StringX} +// @param thisstr The string to append to +// @param i The integer to add +i_DECLIMEX_ void rfString_Append_i(RF_String* thisstr,const int32_t i); + +// @memberof RF_String +// @opadd +// @brief Appends a float to the string +// +// @notinherited{StringX} +// @param thisstr The string to append to +// @param f The float to add +i_DECLIMEX_ void rfString_Append_f(RF_String* thisstr,const float f); + +// @memberof RF_String +// @brief Prepends the parameter String to this string +// +// @notinherited{StringX} +// @lmsFunction +// @param thisstr The string to prepend to +// @param other The string to prepend to this string. @inhtype{String,StringX} @tmpSTR +#if defined(RF_IAMHERE_FOR_DOXYGEN) +i_DECLIMEX_ void rfString_Prepend(RF_String* thisstr,void* other); +#else +i_DECLIMEX_ void i_rfString_Prepend(RF_String* thisstr,void* other); +#define rfString_Prepend(i_THISSTR_,i_OTHERSTR_) i_rfLMS_WRAP2(void,i_rfString_Prepend,i_THISSTR_,i_OTHERSTR_) +#endif + +// @memberof RF_String +// @brief Removes occurences of a substring +// +// @isinherited{StringX} +// Removes a @c number of occurences of a substring from this string, that agree with the given parameters. +// Does not reallocate buffer size +// @lmsFunction +// @param thisstr This string we want to remove from. @inhtype{String,StringX} +// @param rstr The string whose occurences we need to locate and remove from the current string. @inhtype{String,StringX} @tmpSTR +// @param number \rfoptional{0}. The number of occurences to remove. Give @e 0 for all the occurences. +// If the given number is bigger than the actual number of occurences, still all occurences get replaced. +// @param options \rfoptional{0}. Bitflag options denoting some options for the search. Give 0 for the defaults. +// Can have values: +// + @c RF_CASE_IGNORE: If you want the found substring to ignore the case and returns success for any occurence of the string in any case. +// Default search option is to @b match the case. For now this works only for characters of the english language. +// + @c RF_MATCH_WORD: If you want the found substring to be exact. For example an exact search for @e "HELLO" in the string +// @e "HELLOWORLD" would return a failure. Default search is to return any found substring. +// @return Returns true in case of success, and false if the substring was not even found inside the string +#if defined(RF_IAMHERE_FOR_DOXYGEN) +i_DECLIMEX_ char rfString_Remove(void* thisstr,void* rstr,uint32_t number,const char options); +#else + i_DECLIMEX_ char i_rfString_Remove(void* thisstr,void* rstr,uint32_t* number,const char* options); + #ifdef RF_OPTION_DEFAULT_ARGUMENTS + #define rfString_Remove(...) RF_SELECT_FUNC_IF_NARGGT(i_NPSELECT_RF_STRING_REMOVE,4,__VA_ARGS__) + #define i_NPSELECT_RF_STRING_REMOVE1(...) RF_COMPILE_ERROR("message \"Illegal Arguments Number: Function rfString_Remove() accepts from 2 to 4 arguments\"") + #define i_NPSELECT_RF_STRING_REMOVE0(...) RF_SELECT_FUNC(i_SELECT_RF_STRING_REMOVE,__VA_ARGS__) + #define i_SELECT_RF_STRING_REMOVE2(i_THISSTR_,i_REPSTR_) i_rfLMSX_WRAP4(char,i_rfString_Remove,i_THISSTR_,i_REPSTR_,i_RFUI32_(0),i_RFI8_(0)) + #define i_SELECT_RF_STRING_REMOVE3(i_THISSTR_,i_REPSTR_,i_NUMBER_) i_rfLMSX_WRAP4(char,i_rfString_Remove,i_THISSTR_,i_REPSTR_,i_RFUI32_(i_NUMBER_),i_RFI8_(0)) + #define i_SELECT_RF_STRING_REMOVE4(i_THISSTR_,i_REPSTR_,i_NUMBER_,i_OPTIONS_) \ + i_rfLMSX_WRAP4(char,i_rfString_Remove,i_THISSTR_,i_REPSTR_,i_RFUI32_(i_NUMBER_),i_RFI8_(i_OPTIONS_)) + #define i_SELECT_RF_STRING_REMOVE1(...) RF_COMPILE_ERROR("message \"Illegal Arguments Number: Function rfString_Remove() accepts from 2 to 4 arguments\"") + #define i_SELECT_RF_STRING_REMOVE0(...) RF_COMPILE_ERROR("message \"Illegal Arguments Number: Function rfString_Remove() accepts from 2 to 4 arguments\"") + #else + #define rfString_Remove(i_THISSTR_,i_REPSTR_,i_NUMBER_,i_OPTIONS_) i_rfLMSX_WRAP4(char,i_rfString_Remove,i_THISSTR_,i_REPSTR_,i_RFUI32_(i_NUMBER_),i_RFI8_(i_OPTIONS_)) + #endif +#endif + +// @memberof RF_String +// @brief Removes all of the characters of the string except those specified +// +// This string is scanned for the existence of each characters inside the given +// @c keepstr. Any character found there is kept in the original string. All other +// characters are removed. +// @isinherited{StringX} +// @lmsFunction +// @param thisstr The string to remove from @inhtype{String,StringX} +// @param keepstr A string all of whose characters will be kept in @c thisstr @inhtype{String,StringX} @tmpSTR +#ifdef RF_IAMHERE_FOR_DOXYGEN +i_DECLIMEX_ void rfString_KeepOnly(void* thisstr,void* keepstr); +#else +i_DECLIMEX_ void i_rfString_KeepOnly(void* thisstr,void* keepstr); +#define rfString_KeepOnly(i_THISSTR_,I_KEEPSTR_) i_rfLMS_WRAP2(void,i_rfString_KeepOnly,i_THISSTR_,I_KEEPSTR_) +#endif + +// @memberof RF_String +// @brief Removes the first n characters from the start of the string. +// +// @isinherited{StringX} +// @param thisstr The string to prune from. @inhtype{String,StringX} +// @param n The number of characters to remove. Must be a positive integer. +// @return True if n characters got removed and false if there are not enough characters to remove. (in which case the string becomes empty) +i_DECLIMEX_ char rfString_PruneStart(void* thisstr,uint32_t n); + +// @memberof RF_String +// @brief Removes the last n characters from the end of the string +// +// @isinherited{StringX} +// @param thisstr The string to prune from. @inhtype{String,StringX} +// @param n The number of characters to remove. Must be a positive integer. +// @return True if n characters got removed and false if there are not enough characters to remove. (in which case the string becomes empty) +i_DECLIMEX_ char rfString_PruneEnd(void* thisstr,uint32_t n); + +// @memberof RF_String +// @brief Removes characters from one point of the string to another going backwards +// +// @isinherited{StringX} +// Removes n characters from the position p (including the character at p) of the string counting backwards. If there is no space to do so, nothing is done and returns false. +// @param thisstr The string to prune from. @inhtype{String,StringX} +// @param p The position to remove the characters from. Must be a positive integer. Indexing starts from zero. +// @param n The number of characters to remove from the position and back.Must be a positive integer. +// @return Returns true in case of succesfull removal and false in any other case. +i_DECLIMEX_ char rfString_PruneMiddleB(void* thisstr,uint32_t p,uint32_t n); +// @memberof RF_String +// @brief Removes characters from one point of the string to another going forward +// +// @isinherited{StringX} +// Removes n characters from the position p (including the character at p) of the string counting forwards. If there is no space, nothing is done and returns false. +// @param thisstr The string to prune from. @inhtype{String,StringX} +// @param p The position to remove the characters from. Must be a positive integer. Indexing starts from zero. +// @param n The number of characters to remove from the position and on. Must be a positive integer. +// @return Returns true in case of succesfull removal and false in any other case. +i_DECLIMEX_ char rfString_PruneMiddleF(void* thisstr,uint32_t p,uint32_t n); + + +// @memberof RF_String +// @brief Replace all occurences of a String +// +// @notinherited{StringX} +// Replaces all of the specified sstr substring from the String with rstr and reallocates size, unless the new size is smaller +// @lmsFunction +// @param thisstr The string in which to do the replacing +// @param sstr The string to locate and replace from the current string. @inhtype{String,StringX} @tmpSTR +// @param rstr The string with which to replace it. @inhtype{String,StringX} @tmpSTR +// @param number \rfoptional{0}. The number of occurences to replace. Give @e 0 for all the occurences. +// If the given number is bigger than the actual number of occurences, still all occurences get replaced. +// @param options \rfoptional{0}. Bitflag options denoting some options for the string to replace. Give 0 for the defaults. Can have values: +// + @c RF_CASE_IGNORE: If you want to replace any occurence of the substring disregarding CAPS or not. +// Default search option is to @b match the case. For now this works only for characters of the english language. +// + @c RF_MATCH_WORD: If you to replace only exact matches of the substring. For example an exact replace for @e "HELLO" in the string +// @e "HELLOWORLD" would replace nothing. Default is with this flag off. +// @return Returns true in case of success, and false if the substring was not even found inside the string +#if defined(RF_IAMHERE_FOR_DOXYGEN) +i_DECLIMEX_ char rfString_Replace(RF_String* thisstr,void* sstr,void* rstr,const uint32_t number,const char options); +#else +i_DECLIMEX_ char i_rfString_Replace(RF_String* thisstr,void* sstr,void* rstr,const uint32_t* number,const char* options); + #ifdef RF_OPTION_DEFAULT_ARGUMENTS + #define rfString_Replace(...) RF_SELECT_FUNC_IF_NARGGT(i_NPSELECT_RF_STRING_REPLACE,5,__VA_ARGS__) + #define i_NPSELECT_RF_STRING_REPLACE1(...) RF_COMPILE_ERROR("message \"Illegal Arguments Number: Function rfString_Replace() accepts from 3 to 5 arguments\"") + #define i_NPSELECT_RF_STRING_REPLACE0(...) RF_SELECT_FUNC(i_SELECT_RF_STRING_REPLACE,__VA_ARGS__) + #define i_SELECT_RF_STRING_REPLACE3(i_THISSTR_,i_SEARCHSTR_,i_REPSTR_) i_rfLMSX_WRAP5(char,i_rfString_Replace,i_THISSTR_,i_SEARCHSTR_,i_REPSTR_,i_RFUI32_(0),i_RFI8_(0)) + #define i_SELECT_RF_STRING_REPLACE4(i_THISSTR_,i_SEARCHSTR_,i_REPSTR_,i_NUMBER_) \ + i_rfLMSX_WRAP5(char,i_rfString_Replace,i_THISSTR_,i_SEARCHSTR_,i_REPSTR_,i_RFUI32_(i_NUMBER_),i_RFI8_(0)) + #define i_SELECT_RF_STRING_REPLACE5(i_THISSTR_,i_SEARCHSTR_,i_REPSTR_,i_NUMBER_,i_OPTIONS_) \ + i_rfLMSX_WRAP5(char,i_rfString_Replace,i_THISSTR_,i_SEARCHSTR_,i_REPSTR_,i_RFUI32_(i_NUMBER_),i_RFI8_(i_OPTIONS_)) + #define i_SELECT_RF_STRING_REPLACE2(...) RF_COMPILE_ERROR("message \"Illegal Arguments Number: Function rfString_Replace() accepts from 3 to 5 arguments\"") + #define i_SELECT_RF_STRING_REPLACE1(...) RF_COMPILE_ERROR("message \"Illegal Arguments Number: Function rfString_Replace() accepts from 3 to 5 arguments\"") + #define i_SELECT_RF_STRING_REPLACE0(...) RF_COMPILE_ERROR("message \"Illegal Arguments Number: Function rfString_Replace() accepts from 3 to 5 arguments\"") + #else + #define rfString_Replace(i_THISSTR_,i_SEARCHSTR_,i_REPSTR_,i_NUMBER_,i_OPTIONS_) \ + i_rfLMSX_WRAP5(char,i_rfString_Replace,i_THISSTR_,i_SEARCHSTR_,i_REPSTR_,i_RFUI32_(i_NUMBER_),i_RFI8_(i_OPTIONS_)) + #endif +#endif + +// @memberof RF_String +// @brief Removes all characters of a substring only from the start of the String +// +// @isinherited{StringX} +// Searches for and removes each individual character inside the @c sub substring from the +// given String @c thisstr starting from the beginning of the String and until it finds any other character +// @lmsFunction +// @param thisstr The string to search in. @inhtype{String,StringX} +// @param sub The substring to search for. @inhtype{String,StringX} @tmpSTR +// @return Returns true for success and false if none of @c sub characters were found inside the given String +#if defined(RF_IAMHERE_FOR_DOXYGEN) + i_DECLIMEX_ char rfString_StripStart(void* thisstr,void* sub); +#else + i_DECLIMEX_ char i_rfString_StripStart(void* thisstr,void* sub); + #define rfString_StripStart(i_THISSTR_,i_SUBSTR_) i_rfLMSX_WRAP2(char,i_rfString_StripStart,i_THISSTR_,i_SUBSTR_) +#endif +// @memberof RF_String +// @brief Removes all characters of a substring starting from the end of the String +// +// @isinherited{StringX} +// Searches for and removes each individual character inside the @c sub substring from the +// given String @c thisstr starting from the end of the String and until it finds any other character +// @lmsFunction +// @param thisstr The string to search in. @inhtype{String,StringX} +// @param sub The substring to search for. @inhtype{String,StringX} @tmpSTR +// @return Returns true for success and false if none of @c sub characters were found inside the given String +#if defined(RF_IAMHERE_FOR_DOXYGEN) + i_DECLIMEX_ char rfString_StripEnd(void* thisstr,void* sub); +#else + i_DECLIMEX_ char i_rfString_StripEnd(void* thisstr,void* sub); + #define rfString_StripEnd(i_THISSTR_,i_SUBSTR_) i_rfLMSX_WRAP2(char,i_rfString_StripEnd,i_THISSTR_,i_SUBSTR_) +#endif + +// @memberof RF_String +// @brief Removes all characters of a substring from both ends of the given String +// +// @isinherited{StringX} +// Searches for and removes each individual character inside the @c sub substring from the +// given String @c thisstr starting from both the beginning and the end of the String and until it finds any other character +// @lmsFunction +// @param thisstr The string to search in. @inhtype{String,StringX} +// @param sub The substring to search for. @inhtype{String,StringX} @tmpSTR +// @return Returns true for success and false if none of @c sub characters were found inside the given String +#if defined(RF_IAMHERE_FOR_DOXYGEN) + i_DECLIMEX_ char rfString_Strip(void* thisstr,void* sub); +#else + i_DECLIMEX_ char i_rfString_Strip(void* thisstr,void* sub); + #define rfString_Strip(i_THISSTR_,i_SUBSTR_) i_rfLMSX_WRAP2(char,i_rfString_Strip,i_THISSTR_,i_SUBSTR_) +#endif +// @} +/*------------------------------------------------------------------------ RF_String File Descriptor I/O functions-------------------------------------------------------------------------------*/ +// @name String File Descriptor I/O functions +// @{ + +// @memberof RF_String +// @brief Allocates and returns a string from UTF-8 file parsing +// +// @notinherited{StringX} +// Read the file stream @c f until either a newline character or the EOF is reached and saves it as an RF_String +// The file's encoding must be UTF-8.If for some reason (like EOF reached) no string can be read then null is returned +// Given file character stream must be encoded in UTF-8. A check for valide sequence of bytes is performed. +// @param f A valid and open file pointer in read mode from which to read the string. The file's encoding must be UTF-8.A check for valide sequence of bytes is performed. +// @param[out] eof Pass a pointer to a char to receive a true or false value in case the end of file was reached with this initialization +// @return The initialized string or null pointer in case of failure to read the file, or unexpected data (non-UTF8 encoded string) +i_DECLIMEX_ RF_String* rfString_Create_fUTF8(FILE* f, char* eof); +// @memberof RF_String +// @brief Initializes a string from UTF-8 file parsing +// +// @notinherited{StringX} +// Read the file stream @c f until either a newline character or the EOF is reached and saves it as an RF_String +// The file's encoding must be UTF-8.If for some reason (like EOF reached) no string can be read then null is returned +// Given file character stream must be encoded in UTF-8. A check for valide sequence of bytes is performed. +// @param str The extended string to initialize +// @param f A valid and open file pointer in read mode from which to read the string. The file's encoding must be UTF-8.A check for valide sequence of bytes is performed. +// @param[out] eof Pass a pointer to a char to receive a true or false value in case the end of file was reached with this initialization +// @return Returns either a positive number for succesfull initialization that represents the bytes read from the file. +// If there was a problem an error is returned. Possible errors are any of those that @ref rfFReadLine_UTF8() can produce. +i_DECLIMEX_ int32_t rfString_Init_fUTF8(RF_String* str,FILE* f, char* eof); + +// @memberof RF_String +// @brief Assigns to a string from UTF-8 file parsing +// +// @notinherited{StringX} +// Read the file stream @c f until either a newline character or the EOF is reached and assigns it to an RF_StringX +// The file's encoding must be UTF-8.If for some reason (like EOF reached) no string can be read then null is returned +// Given file character stream must be encoded in UTF-8. A check for valide sequence of bytes is performed. +// @param str The extended string to assign to +// @param f A valid and open file pointer in read mode from which to read the string. The file's encoding must be UTF-8.A check for valide sequence of bytes is performed. +// @param[out] eof Pass a pointer to a char to receive a true or false value in case the end of file was reached with this assignment +// @return Returns either a positive number for succesfull assignment that represents the bytes read from the file. +// If there was a problem an error is returned. Possible errors are any of those that @ref rfFReadLine_UTF8() can produce. +i_DECLIMEX_ int32_t rfString_Assign_fUTF8(RF_String* str,FILE* f, char* eof); +// @memberof RF_String +// @brief Appends to a string from UTF-8 file parsing +// +// @notinherited{StringX} +// Read the file stream @c f until either a newline character or the EOF is reached and appends it to an RF_StringX +// The file's encoding must be UTF-8.If for some reason (like EOF reached) no string can be read then null is returned +// Given file character stream must be encoded in UTF-8. A check for valid sequence of bytes is performed. +// @param str The extended string to append to +// @param f A valid and open file pointer in read mode from which to read the string. The file's encoding must be UTF-8.A check for valide sequence of bytes is performed. +// @param[out] eof Pass a pointer to a char to receive a true or false value in case the end of file was reached with this appending +// @return Returns either a positive number for succesfull appending that represents the bytes read from the file. +// If there was a problem an error is returned. Possible errors are any of those that @ref rfFReadLine_UTF8() can produce. +i_DECLIMEX_ int32_t rfString_Append_fUTF8(RF_String* str,FILE* f, char* eof); + +// @memberof RF_String +// @cppnotctor +// @brief Allocates and returns a string from UTF-16 file parsing +// +// @notinherited{StringX} +// Read the file stream @c f until either a newline character or the EOF is reached and saves it as an RF_StringX +// The file's encoding must be UTF-16.If for some reason (like EOF reached) no string can be read then null is returned. A check for a valid sequence of bytes is performed. +// @param f A valid and open file pointer in read mode from which to read the string. The file's encoding must be UTF-16. +// @param endianess A flag that determines in what endianess the UTF-16 file is encoded in. Possible values here are +// @c RF_LITTLE_ENDIAN and @c RF_BIG_ENDIAN. +// @param[out] eof Pass a pointer to a char to receive a true or false value in case the end of file was reached with this initialization +// @return The initialized string or null pointer in case of failure to read the file +i_DECLIMEX_ RF_String* rfString_Create_fUTF16(FILE* f, char endianess,char* eof); +// @memberof RF_String +// @brief Initializes a string from UTF-16 file parsing +// +// @notinherited{StringX} +// Read the file stream @c f until either a newline character or the EOF is reached and saves it as an RF_StringX +// The file's encoding must be UTF-16.If for some reason (like EOF reached) no string can be read then null is returned. A check for a valid sequence of bytes is performed. +// @param str The extended string to initialize +// @param f A valid and open file pointer in read mode from which to read the string. The file's encoding must be UTF-16. +// @param endianess A flag that determines in what endianess the UTF-16 file is encoded in. Possible values here are +// @c RF_LITTLE_ENDIAN and @c RF_BIG_ENDIAN. +// @param[out] eof Pass a pointer to a char to receive a true or false value in case the end of file was reached with this initialization +// @return Returns either a positive number for succesfull initialization that represents the bytes read from the file. +// If there was a problem an error is returned. Possible errors are any of those that @ref rfFReadLine_UTF16LE() can produce. +i_DECLIMEX_ int32_t rfString_Init_fUTF16(RF_String* str,FILE* f, char endianess,char* eof); + +// @memberof RF_String +// @brief Appends the contents of a UTF-16 file a String +// +// @notinherited{StringX} +// Read the file stream @c f until either a newline character or the EOF is reached and appends it to an RF_StringX +// The file's encoding must be UTF-16.If for some reason (like EOF reached) no string can be read then null is returned. A check for a valid sequence of bytes is performed. +// @param str The extended string to append to +// @param f A valid and open file pointer in read mode from which to read the string. The file's encoding must be UTF-16. +// @param endianess A flag that determines in what endianess the UTF-16 file is encoded in. Possible values here are +// @c RF_LITTLE_ENDIAN and @c RF_BIG_ENDIAN. +// @param[out] eof Pass a pointer to a char to receive a true or false value in case the end of file was reached with this appending +// @return Returns either a positive number for succesfull appending that represents the bytes read from the file. +// If there was a problem an error is returned. Possible errors are any of those that @ref rfFReadLine_UTF16LE() can produce. +i_DECLIMEX_ int32_t rfString_Append_fUTF16(RF_String* str,FILE* f, char endianess,char* eof); +// @memberof RF_String +// @brief Assigns the contents of a UTF-16 file to an already initialized string +// +// @notinherited{StringX} +// Read the file stream @c f until either a newline character or the EOF is reached and assigns it to an RF_StringX +// The file's encoding must be UTF-16.If for some reason (like EOF reached) no string can be read then null is returned. A check for a valid sequence of bytes is performed. +// @param str The extended string to assign to +// @param f A valid and open file pointer in read mode from which to read the string. The file's encoding must be UTF-16. +// @param endianess A flag that determines in what endianess the UTF-16 file is encoded in. Possible values here are +// @c RF_LITTLE_ENDIAN and @c RF_BIG_ENDIAN. +// @param[out] eof Pass a pointer to a char to receive a true or false value in case the end of file was reached with this assignment +// @return Returns either a positive number for succesfull assignment that represents the bytes read from the file. +// If there was a problem an error is returned. Possible errors are any of those that @ref rfFReadLine_UTF16LE() can produce. +i_DECLIMEX_ int32_t rfString_Assign_fUTF16(RF_String* str,FILE* f, char endianess,char* eof); + +// @memberof RF_String +// @cppnotctor +// @brief Allocates and returns a string from UTF-32 file parsing +// +// @notinherited{StringX} +// Read the file stream @c f until either a newline character or the EOF is reached and saves it as an RF_StringX +// The file's encoding must be UTF-32.If for some reason (like EOF reached) no string can be read then null is returned. A check for a valid sequence of bytes is performed. +// @param f A valid and open file pointer in read mode from which to read the string. The file's encoding must be UTF-32. +// @param endianess A flag that determines in what endianess the UTF-32 file is encoded in. Possible values here are +// @c RF_LITTLE_ENDIAN and @c RF_BIG_ENDIAN. +// @param[out] eof Pass a pointer to a char to receive a true or false value in case the end of file was reached with this initialization +// @return The initialized string or null pointer in case of failure to read the file +i_DECLIMEX_ RF_String* rfString_Create_fUTF32(FILE* f,char endianess, char* eof); +// @memberof RF_String +// @brief Initializes a string from UTF-32 file parsing +// +// @notinherited{StringX} +// Read the file stream @c f until either a newline character or the EOF is reached and saves it as an RF_StringX +// The file's encoding must be UTF-32.If for some reason (like EOF reached) no string can be read then null is returned. A check for a valid sequence of bytes is performed. +// @param str The extended string to initialize +// @param f A valid and open file pointer in read mode from which to read the string. The file's encoding must be UTF-32. +// @param endianess A flag that determines in what endianess the UTF-32 file is encoded in. Possible values here are +// @c RF_LITTLE_ENDIAN and @c RF_BIG_ENDIAN. +// @param[out] eof Pass a pointer to a char to receive a true or false value in case the end of file was reached with this initialization +// @return Returns either a positive number for succesfull initialization that represents the bytes read from the file. +// If there was a problem an error is returned. Possible errors are any of those that @ref rfFReadLine_UTF32LE() can produce. +i_DECLIMEX_ int32_t rfString_Init_fUTF32(RF_String* str,FILE* f,char endianess, char* eof); +// @memberof RF_String +// @brief Assigns the contents of a UTF-32 file to a string +// +// @notinherited{StringX} +// Read the file stream @c f until either a newline character or the EOF is reached and assigns it as the contents of the given RF_StringX +// The file's encoding must be UTF-32.If for some reason (like EOF reached) no string can be read then null is returned. A check for a valid sequence of bytes is performed. +// @param str The extended string to assign to +// @param f A valid and open file pointer in read mode from which to read the string. The file's encoding must be UTF-32. +// @param endianess A flag that determines in what endianess the UTF-32 file is encoded in. Possible values here are +// @c RF_LITTLE_ENDIAN and @c RF_BIG_ENDIAN. +// @param[out] eof Pass a pointer to a char to receive a true or false value in case the end of file was reached with this assignment +// @return Returns either a positive number for succesfull assignment that represents the bytes read from the file. +// If there was a problem an error is returned. Possible errors are any of those that @ref rfFReadLine_UTF32LE() can produce. +i_DECLIMEX_ int32_t rfString_Assign_fUTF32(RF_String* str,FILE* f,char endianess, char* eof); +// @memberof RF_String +// @brief Appends the contents of a UTF-32 file to a string +// +// @notinherited{StringX} +// Read the file stream @c f until either a newline character or the EOF is reached and appends to the given RF_StringX +// The file's encoding must be UTF-32.If for some reason (like EOF reached) no string can be read then null is returned. A check for a valid sequence of bytes is performed. +// @param str The extended string to append to +// @param f A valid and open file pointer in read mode from which to read the string. The file's encoding must be UTF-32. +// @param endianess A flag that determines in what endianess the UTF-32 file is encoded in. Possible values here are +// @c RF_LITTLE_ENDIAN and @c RF_BIG_ENDIAN. +// @param[out] eof Pass a pointer to a char to receive a true or false value in case the end of file was reached with this appending +// @return Returns either a positive number for succesfull appending that represents the bytes read from the file. +// If there was a problem an error is returned. Possible errors are any of those that @ref rfFReadLine_UTF32LE() can produce. +i_DECLIMEX_ int32_t rfString_Append_fUTF32(RF_String* str,FILE* f,char endianess, char* eof); + +// @memberof RF_String +// @brief Writes a string to a file depending on the given encoding +// +// @isinherited{StringX} +// This function shall output the string @c s into the file descriptor @c f in the given @c encoding . +// @lmsFunction +// @param s The string to write to the file @inhtype{String,StringX} @tmpSTR +// @param f A valid and open file pointer into which to write the string. +// @param encoding \rfoptional{@c RF_UTF8} The encoding of the file. Default is @c RF_UTF8. Can be one of: +// + @c RF_UTF8: For Unicode UTF-8 encoding +// + @c RF_UTF16_BE: For Unicode UTF-16 encoding in Big Endian endianess +// + @c RF_UTF16_LE: For Unicode UTF-16 encoding in Little Endian endianess +// + @c RF_UTF32_BE: For Unicode UTF-32 encoding in Big Endian endianess +// + @c RF_UTF32_LE: For Unicode UTF-32 encoding in Little Endian endianess +// @return Returns @c RF_SUCCESS for succesfull writting and error otherwise. Possible errors are: +// + @c RE_FILE_WRITE: There was an unknown write error +// + @c RE_FILE_WRITE_BLOCK: The write failed because the file was occupied by another thread and the no block flag was set +// + @c RE_FILE_BAD: The file descriptor @c f was corrupt +// + @c RE_FILE_TOOBIG: The file's size exceeds the system limiti +// + @c RE_INTERRUPT: Writting failed due to a system interrupt +// + @c RE_FILE_IO: Writting failed because of a physical I/O error +// + @c RE_FILE_NOSPACE: Writting failed because the device containing the file had no free space +// + @c RE_FILE_NOT_FILE: Writting failed because the given file descriptor @c f is either non existen or not a file +#if defined(RF_IAMHERE_FOR_DOXYGEN) + i_DECLIMEX_ int32_t rfString_Fwrite(void* s,FILE* f,char encoding); +#else + i_DECLIMEX_ int32_t i_rfString_Fwrite(void* s,FILE* f,char* encoding); + #ifdef RF_OPTION_DEFAULT_ARGUMENTS + #define rfString_Fwrite(...) RF_SELECT_FUNC_IF_NARGGT(i_NPSELECT_RF_STRING_FWRITE,3,__VA_ARGS__) + #define i_NPSELECT_RF_STRING_FWRITE1(...) RF_COMPILE_ERROR("message \"Illegal Arguments Number: Function rfString_Fwrite() accepts from 2 to 3 arguments\"") + #define i_NPSELECT_RF_STRING_FWRITE0(...) RF_SELECT_FUNC(i_SELECT_RF_STRING_FWRITE,__VA_ARGS__) + #define i_SELECT_RF_STRING_FWRITE3(i_STR_,i_FILE_,i_ENCODING_) i_rfLMSX_WRAP3(int32_t,i_rfString_Fwrite,i_STR_,i_FILE_,i_RFI8_(i_ENCODING_)) + #define i_SELECT_RF_STRING_FWRITE2(i_STR_,i_FILE_) i_rfLMSX_WRAP3(int32_t,i_rfString_Fwrite,i_STR_,i_FILE_,i_RFI8_(RF_UTF8)) + #define i_SELECT_RF_STRING_FWRITE1(i_STR_,i_FILE_) RF_COMPILE_ERROR("message \"Illegal Arguments Number: Function rfString_Fwrite() accepts from 2 to 3 arguments\"") + #define i_SELECT_RF_STRING_FWRITE0(i_STR_,i_FILE_) RF_COMPILE_ERROR("message \"Illegal Arguments Number: Function rfString_Fwrite() accepts from 2 to 3 arguments\"") + #else + #define rfString_Fwrite_fUTF8(i_STR_,i_FILE_,i_ENCODING_) i_rfLMSX_WRAP3(int32_t,i_rfString_Fwrite,i_STR_,i_FILE_,i_RFI8_(i_ENCODING_)) + #endif +#endif + + +// @} +// closing the String File I/o functions + +#ifdef __cplusplus +}// closing bracket for calling from C++ +#endif + +#else // end of the strings module include + #error Attempted to include Refu String manipulation with the String module flag off. Rebuild the library with that option added if you need to include them +#endif + +#endif// include guards end +