Prechádzať zdrojové kódy

refactor: 调整目录相关函数的定义

SongZihuan 3 rokov pred
rodič
commit
91283acc28

+ 1 - 2
CMakeLists.txt

@@ -62,8 +62,7 @@ set(_print_dir ${PRINT_DIR_INFO})
 
 include(tool)
 
-include(InstallDir)
-include(WindowsInstall)
+include(directory)
 
 if (_print_dir)
     set(PRINT_DIR_INFO OFF CACHE BOOL "Print install and build dirs info." FORCE)

+ 0 - 0
cmake/WindowsInstall.cmake → cmake/deps-install.cmake


+ 1 - 0
cmake/deps.cmake

@@ -1,4 +1,5 @@
 include_guard(GLOBAL)
+include(deps-install)
 
 set(PRINT_DEPS_INFO ON CACHE BOOL "Print deps info.")  # 默认设定为 ON
 set(_print ${PRINT_DEPS_INFO})

+ 1 - 1
cmake/InstallDir.cmake → cmake/directory.cmake

@@ -1,5 +1,5 @@
 #[[
-文件名: InstallDir.cmake
+文件名: directory.cmake
 设置安装路径的程序
 ]]
 

+ 3 - 5
include/core/core-init.h

@@ -5,15 +5,13 @@
 
 namespace aFuncore {
     struct InitInfo {
-        const std::string &base_dir;
         aFuntool::LogFactory &factor;
         aFuntool::Logger &core_logger;
         aFuntool::Logger &sys_logger;
 
-        AFUN_INLINE InitInfo(const std::string &base_dir_,
-                        aFuntool::LogFactory &factor_,
-                        aFuntool::Logger &core_logger_,
-                        aFuntool::Logger &sys_logger_);
+        AFUN_INLINE InitInfo(aFuntool::LogFactory &factor_,
+                             aFuntool::Logger &core_logger_,
+                             aFuntool::Logger &sys_logger_);
 
     };
 

+ 4 - 5
include/core/core-init.inline.h

@@ -4,11 +4,10 @@
 #include "core-init.h"
 
 namespace aFuncore {
-    InitInfo::InitInfo(const std::string &base_dir_,
-                              aFuntool::LogFactory &factor_,
-                              aFuntool::Logger &core_logger_,
-                              aFuntool::Logger &sys_logger_) :
-        base_dir{base_dir_}, factor{factor_}, core_logger{core_logger_}, sys_logger{sys_logger_} {
+    InitInfo::InitInfo(aFuntool::LogFactory &factor_,
+                       aFuntool::Logger &core_logger_,
+                       aFuntool::Logger &sys_logger_) :
+        factor{factor_}, core_logger{core_logger_}, sys_logger{sys_logger_} {
 
     }
 

+ 4 - 5
include/interface/it-init.h

@@ -7,11 +7,10 @@ namespace aFunit {
     struct aFunInitInfo : public aFuncore::InitInfo {
         aFuntool::Logger &afun_logger;
 
-        AFUN_INLINE aFunInitInfo(const std::string &base_dir_,
-                            aFuntool::LogFactory &factor_,
-                            aFuntool::Logger &afun_logger_,
-                            aFuntool::Logger &core_logger_,
-                            aFuntool::Logger &sys_logger_);
+        AFUN_INLINE aFunInitInfo(aFuntool::LogFactory &factor_,
+                                 aFuntool::Logger &afun_logger_,
+                                 aFuntool::Logger &core_logger_,
+                                 aFuntool::Logger &sys_logger_);
     };
 
     AFUN_LANG_EXPORT extern aFuntool::Logger *aFunLogger;

+ 5 - 6
include/interface/it-init.inline.h

@@ -4,12 +4,11 @@
 #include "it-init.h"
 
 namespace aFunit {
-    aFunInitInfo::aFunInitInfo(const std::string &base_dir_,
-                                      aFuntool::LogFactory &factor_,
-                                      aFuntool::Logger &afun_logger_,
-                                      aFuntool::Logger &core_logger_,
-                                      aFuntool::Logger &sys_logger_) :
-        InitInfo(base_dir_, factor_, core_logger_, sys_logger_), afun_logger{afun_logger_} {
+    aFunInitInfo::aFunInitInfo(aFuntool::LogFactory &factor_,
+                               aFuntool::Logger &afun_logger_,
+                               aFuntool::Logger &core_logger_,
+                               aFuntool::Logger &sys_logger_) :
+        InitInfo(factor_, core_logger_, sys_logger_), afun_logger{afun_logger_} {
 
     }
 

+ 2 - 0
include/tool/aFuntool.h

@@ -17,6 +17,8 @@
 #include "tool-exit.h"
 #include "byte.h"
 #include "dlc.h"
+#include "directory.h"
+#include "encoding.h"
 #include "file.h"
 #include "hash.h"
 #include "md5.h"

+ 17 - 0
include/tool/directory.h

@@ -0,0 +1,17 @@
+#ifndef AFUN_DIRECTORY_H
+#define AFUN_DIRECTORY_H
+#include "aFunToolExport.h"
+#include "iostream"
+
+/* 文件处理工具 */
+namespace aFuntool {
+    AFUN_TOOL_EXPORT std::string joinPath(const std::string &path, const std::string &name, const std::string &suffix);
+    AFUN_TOOL_EXPORT std::string getFileName(const std::string &path);
+    AFUN_TOOL_EXPORT std::string getFilePathName(const std::string &path);
+    AFUN_TOOL_EXPORT std::string getFilePath(const std::string &path_1, int dep);
+    AFUN_TOOL_EXPORT std::string getFileSuffix(const std::string &path);
+    AFUN_TOOL_EXPORT std::string fileNameToVar(const std::string &name);
+    AFUN_TOOL_EXPORT std::string findPath(const std::string &path, const std::string &env);
+    AFUN_TOOL_EXPORT std::string getExePath();
+}
+#endif //AFUN_DIRECTORY_H

+ 14 - 0
include/tool/encoding.h

@@ -0,0 +1,14 @@
+#ifndef AFUN_ENCODING_H
+#define AFUN_ENCODING_H
+#include <iostream>
+#include "aFunToolExport.h"
+#include "macro.h"
+
+namespace aFuntool {
+    AFUN_TOOL_EXPORT bool isCharUTF8(const char *str);
+    AFUN_INLINE bool isCharUTF8(const std::string &str);
+}
+
+#include "encoding.inline.h"
+
+#endif //AFUN_ENCODING_H

+ 11 - 0
include/tool/encoding.inline.h

@@ -0,0 +1,11 @@
+#ifndef AFUN_ENCODING_INLINE_H
+#define AFUN_ENCODING_INLINE_H
+#include "encoding.h"
+
+namespace aFuntool {
+    bool isCharUTF8(const std::string &str) {
+        return isCharUTF8(str.c_str());
+    }
+}
+
+#endif //AFUN_ENCODING_INLINE_H

+ 3 - 12
include/tool/file.h

@@ -1,25 +1,16 @@
-#ifndef AFUN_FILE_H
+#ifndef AFUN_FILE_H
 #define AFUN_FILE_H
+#include "iostream"
 #include "aFunToolExport.h"
 
 /* 文件处理工具 */
 namespace aFuntool {
     AFUN_TOOL_EXPORT int checkFile(const std::string &path);
     AFUN_TOOL_EXPORT time_t getFileMTime(const std::string &path);
-    AFUN_TOOL_EXPORT std::string joinPath(const std::string &path, const std::string &name, const std::string &suffix);
-    AFUN_TOOL_EXPORT std::string getFileName(const std::string &path);
-    AFUN_TOOL_EXPORT std::string getFilePathName(const std::string &path);
-    AFUN_TOOL_EXPORT std::string getFilePath(const std::string &path_1, int dep);
-    AFUN_TOOL_EXPORT std::string getFileSurfix(const std::string &path);
-    AFUN_TOOL_EXPORT std::string fileNameToVar(const std::string &name);
-    AFUN_TOOL_EXPORT std::string findPath(const std::string &path, const std::string &env);
-    AFUN_TOOL_EXPORT std::string getHomePath();
-    AFUN_TOOL_EXPORT std::string getExePath();
     AFUN_TOOL_EXPORT uintmax_t getFileSize(const std::string &path);
-    AFUN_TOOL_EXPORT bool isCharUTF8(const char *str);
-    AFUN_TOOL_EXPORT bool isCharUTF8(const std::string &str);
     AFUN_TOOL_EXPORT FILE *fileOpen(const std::string &path_, const char *mode_);
     AFUN_TOOL_EXPORT FILE *fileOpen(const char *path_, const char *mode_);
     AFUN_TOOL_EXPORT int fileClose(FILE *file);
 }
+
 #endif //AFUN_FILE_H

+ 26 - 26
src/CMakeLists.txt

@@ -27,29 +27,29 @@ add_subdirectory(tool)
 add_subdirectory(core)  # core 依赖 tool
 add_subdirectory(interface)  # interface 依赖 core
 
-# source在子目录中被使用, 为了避免子目录访问到source, 子目录将在此前面被执行
-file(GLOB source
-     LIST_DIRECTORIES FALSE
-     ${CMAKE_CURRENT_LIST_DIR}/*.cpp)
-
-file(GLOB private_h
-     LIST_DIRECTORIES FALSE
-     ${CMAKE_CURRENT_LIST_DIR}/*.h)
-
-add_executable(aFun-xx "")  # xx表示均为动态链接
-add_executable(aFun-ct "" ../include/tool/macro.h)  # ct表示均静态链接
-set(aFunList aFun-xx aFun-ct)
-
-foreach(tgt IN LISTS aFunList)
-    target_sources(${tgt} PRIVATE ${source} ${private_h} ${include_h})
-    target_include_directories(${tgt} PRIVATE ${PROJECT_SOURCE_DIR}/include)
-    define_FILENAME(${tgt})
-endforeach()
-
-target_link_libraries(aFun-xx PUBLIC rt-shared FFlags::fflags)
-target_link_libraries(aFun-ct PUBLIC rt-static FFlags::fflags)
-
-install(TARGETS aFun-xx aFun-ct
-        RUNTIME DESTINATION ${INSTALL_BINDIR} COMPONENT dev
-        PUBLIC_HEADER DESTINATION ${INSTALL_INCLUDEDIR} COMPONENT dev
-        PRIVATE_HEADER DESTINATION ${INSTALL_INCLUDEDIR} COMPONENT dev)
+## source在子目录中被使用, 为了避免子目录访问到source, 子目录将在此前面被执行
+#file(GLOB source
+#     LIST_DIRECTORIES FALSE
+#     ${CMAKE_CURRENT_LIST_DIR}/*.cpp)
+#
+#file(GLOB private_h
+#     LIST_DIRECTORIES FALSE
+#     ${CMAKE_CURRENT_LIST_DIR}/*.h)
+#
+#add_executable(aFun-xx "")  # xx表示均为动态链接
+#add_executable(aFun-ct "")  # ct表示均静态链接
+#set(aFunList aFun-xx aFun-ct)
+#
+#foreach(tgt IN LISTS aFunList)
+#    target_sources(${tgt} PRIVATE ${source} ${private_h} ${include_h})
+#    target_include_directories(${tgt} PRIVATE ${PROJECT_SOURCE_DIR}/include)
+#    define_FILENAME(${tgt})
+#endforeach()
+#
+#target_link_libraries(aFun-xx PUBLIC rt-shared FFlags::fflags)
+#target_link_libraries(aFun-ct PUBLIC rt-static FFlags::fflags)
+#
+#install(TARGETS aFun-xx aFun-ct
+#        RUNTIME DESTINATION ${INSTALL_BINDIR} COMPONENT dev
+#        PUBLIC_HEADER DESTINATION ${INSTALL_INCLUDEDIR} COMPONENT dev
+#        PRIVATE_HEADER DESTINATION ${INSTALL_INCLUDEDIR} COMPONENT dev)

+ 0 - 2
src/core/core-init.cpp

@@ -16,8 +16,6 @@ namespace aFuncore {
         aFuntool::getEndian();
         if (setlocale(LC_ALL, "") == nullptr)
             return false;
-        if (info->base_dir.empty())
-            return false;
 
         setCoreLogger(&info->core_logger);
         aFuntool::setSysLogger(&info->sys_logger);

+ 158 - 0
src/tool/directory.cpp

@@ -0,0 +1,158 @@
+/*
+ * 文件名: file.c
+ * 目标: 关于文件读取的实用函数
+ */
+
+#include <cctype>
+
+#include "directory.h"
+#include "path.h"
+#include "str.h"
+#include "log.h"
+#include "tool-stdio.h"
+
+#ifdef aFunWIN32_NO_CYGWIN
+#ifdef _MSC_VER
+#pragma warning(disable : 5105)  // 关闭 5105 的警告输出 (Windows.h中使用)
+#endif
+#include <Windows.h>
+#else
+#include <unistd.h>
+#endif
+
+namespace aFuntool {
+#ifdef aFunWIN32_NO_CYGWIN
+    typedef wchar_t aFun_path;
+#else
+    typedef char aFun_path;
+#endif
+
+    /**
+     * 拼接路径
+     * @param path 路径
+     * @param name 文件名
+     * @param suffix 后缀
+     * @return
+     */
+    std::string joinPath(const std::string &path, const std::string &name, const std::string &suffix) {
+        std::string name_suffix = name + suffix;
+        if (!path.empty() && *(path.end()) == SEP_CH)
+            return path + name_suffix;
+        else if (!path.empty())
+            return path + SEP + name_suffix;
+        return name_suffix;
+    }
+
+    /**
+     * 给定路径获取该路径所指定的文件名
+     */
+    std::string getFileName(const std::string &path){
+        int sep = 0;
+        if (*(path.end()) == SEP_CH)  // 若路径的最后一个字符为SEP, 则忽略此SEP
+            sep = -1;
+
+        auto slash = path.find_last_of('/');
+        if (slash == std::string::npos)
+            slash = 0;
+        else
+            slash++;
+
+        return path.substr(path.size() - slash + sep, slash);
+    }
+
+    /**
+     * 获取 文件路径+文件名(排除后缀)
+     */
+    std::string getFilePathName(const std::string &path){
+        auto point = path.find_last_of('.');
+        if (point == std::string::npos)
+            return path;
+        return path.substr(point);
+    }
+
+    /**
+     * 获取文件路径(不包含文件名)
+     */
+    std::string getFilePath(const std::string &path, int dep){
+        std::string::size_type point = path.size();
+        for (int i = 0; i < dep; i++) {
+            auto tmp = path.rfind(SEP_CH, point - 1);
+            if (tmp == std::string::npos)
+                break;
+            point = tmp;
+        }
+        return path.substr(0, point);
+    }
+
+    /**
+     * 获取文件后缀
+     */
+    std::string getFileSuffix(const std::string &path) {
+        auto point = path.find_last_of('.');
+        if (point == std::string::npos)
+            point = 0;
+        else
+            point++;
+
+        std::string ret = path.substr(path.size() - point, point);
+        return ret;
+    }
+
+    /**
+     * 把一个文件名转换为合法的变量名(替换不合法字符为_)
+     * @param name 路径
+     * @param need_free 是否需要释放
+     */
+    std::string fileNameToVar(const std::string &name){
+        char *var = strCopy(name.c_str());  // 复制新的数据再修改
+
+        if (!isalpha(*var) && *var != '_')
+            var = strJoin("_", var, false, true);
+        for (char *tmp = var; *tmp != 0; tmp++)
+            if (!isalnum(*tmp) &&'_' != *tmp)
+                *tmp = '_';
+        std::string ret = var;
+        safeFree(var);
+        return ret;
+    }
+
+    /**
+     * 转换路径为合法路径(相对路径->绝对路径, 绝对路径保持不变)
+     * @param path 文件路径
+     * @param env 环境 必须以 / 结尾
+     * @param need_free 是否需要释放 path
+     */
+    std::string findPath(const std::string &path, const std::string &env){
+#ifdef __linux
+        if (path[0] != SEP_CH) // 不以 / 开头
+#else
+        if (!(isupper(path[0]) && (path)[1] == ':'))  // 不以盘符开头
+#endif
+            return env + path;  // 调整为相对路径模式
+        return path;
+    }
+
+    /**
+     * 获取可执行程序目录
+     * @param dep 从可执行程序往回跳出的层数
+     */
+    std::string getExePath() {
+        aFun_path exe_path[218] = {0};
+#ifdef aFunWIN32_NO_CYGWIN
+        DWORD ret = GetModuleFileNameW(nullptr, exe_path, 217);  // 预留一位给NUL
+        if (ret == 0 || wcslen(exe_path) == 0)
+            return "";
+        char *path = nullptr;
+        if (convertFromWideByte(&path, exe_path, CP_UTF8) == 0)
+            return "";
+        std::string re = path;
+        safeFree(path);
+        return re;
+#else
+        ssize_t ret =  readlink("/proc/self/exe", exe_path, 217);  // 预留一位给NUL
+        if (ret == -1 || strlen(exe_path) == 0)
+            return "";
+        return exe_path;
+#endif
+    }
+}

+ 39 - 0
src/tool/encoding.cpp

@@ -0,0 +1,39 @@
+#include "tool-type.h"
+#include "encoding.h"
+
+namespace aFuntool {
+    /**
+     * 检查给定字符串是否utf-8编码
+     * @param str 字符串
+     */
+    bool isCharUTF8(const char *str) {
+        int code = 0;  // utf-8 多字节数
+        for (const char *ch = str; *ch != NUL; ch++) {
+            unsigned char c = *ch;
+            unsigned char c_ = ~c;
+
+            assertFatalErrorLog(code >= 0 && code <= 5, aFunSysLogger, 2, "str = %s", str);
+            if (code == 0) {
+                if ((c_ & 0xFC) == 0 && (c & 0x02) == 0)  // 检查是否为1111110x, 先对其取反, 使用0xFC掩码检查前6位是否为0, 然后单独检查倒数第二位是否为0
+                    code = 5;  // 剩余 5 个字节
+                else if ((c_ & 0xF8) == 0 && (c & 0x04) == 0)
+                    code = 4;  // 剩余 4 个字节
+                else if ((c_ & 0xF0) == 0 && (c & 0x08) == 0)
+                    code = 3;  // 剩余 3 个字节
+                else if ((c_ & 0xE0) == 0 && (c & 0x10) == 0)
+                    code = 2;  // 剩余 2 个字节
+                else if ((c_ & 0xC0) == 0 && (c & 0x20) == 0)
+                    code = 1;  // 剩余 1 个字节
+                else if ((c & 0x80) == 0)  // 检查最高位是否为0
+                    code = 0;
+                else
+                    return false;
+            } else if ((c_ & 0x80) == 0 && (c & 0x40) == 0)
+                code--;
+            else
+                return false;
+        }
+
+        return true;
+    }
+}

+ 0 - 205
src/tool/file.cpp

@@ -1,18 +1,5 @@
-/*
- * 文件名: file.c
- * 目标: 关于文件读取的实用函数
- */
-
-#include <sys/stat.h>
-#include <cctype>
-#include <cstdio>
-#include <cstdlib>
-
 #include "tool-type.h"
 #include "file.h"
-#include "path.h"
-#include "str.h"
-#include "log.h"
 #include "tool-stdio.h"
 
 #ifdef aFunWIN32_NO_CYGWIN
@@ -89,159 +76,6 @@ namespace aFuntool {
         return stat.st_mtime;
     }
 
-    /**
-     * 拼接路径
-     * @param path 路径
-     * @param name 文件名
-     * @param suffix 后缀
-     * @return
-     */
-    std::string joinPath(const std::string &path, const std::string &name, const std::string &suffix) {
-        std::string name_suffix = name + suffix;
-        if (!path.empty() && *(path.end()) == SEP_CH)
-            return path + name_suffix;
-        else if (!path.empty())
-            return path + SEP + name_suffix;
-        return name_suffix;
-    }
-
-    /**
-     * 给定路径获取该路径所指定的文件名
-     */
-    std::string getFileName(const std::string &path){
-        int sep = 0;
-        if (*(path.end()) == SEP_CH)  // 若路径的最后一个字符为SEP, 则忽略此SEP
-            sep = -1;
-
-        auto slash = path.find_last_of('/');
-        if (slash == std::string::npos)
-            slash = 0;
-        else
-            slash++;
-
-        return path.substr(path.size() - slash + sep, slash);
-    }
-
-    /**
-     * 获取 文件路径+文件名(排除后缀)
-     */
-    std::string getFilePathName(const std::string &path){
-        auto point = path.find_last_of('.');
-        if (point == std::string::npos)
-            return path;
-        return path.substr(point);
-    }
-
-    /**
-     * 获取文件路径(不包含文件名)
-     */
-    std::string getFilePath(const std::string &path, int dep){
-        std::string::size_type point = path.size();
-        for (int i = 0; i < dep; i++) {
-            auto tmp = path.rfind(SEP_CH, point - 1);
-            if (tmp == std::string::npos)
-                break;
-            point = tmp;
-        }
-        return path.substr(0, point);
-    }
-
-    /**
-     * 获取文件后缀
-     */
-    std::string getFileSurfix(const std::string &path) {
-        auto point = path.find_last_of('.');
-        if (point == std::string::npos)
-            point = 0;
-        else
-            point++;
-
-        std::string ret = path.substr(path.size() - point, point);
-        return ret;
-    }
-
-    /**
-     * 把一个文件名转换为合法的变量名(替换不合法字符为_)
-     * @param name 路径
-     * @param need_free 是否需要释放
-     */
-    std::string fileNameToVar(const std::string &name){
-        char *var = strCopy(name.c_str());  // 复制新的数据再修改
-
-        if (!isalpha(*var) && *var != '_')
-            var = strJoin("_", var, false, true);
-        for (char *tmp = var; *tmp != 0; tmp++)
-            if (!isalnum(*tmp) &&'_' != *tmp)
-                *tmp = '_';
-        std::string ret = var;
-        safeFree(var);
-        return ret;
-    }
-
-    /**
-     * 转换路径为合法路径(相对路径->绝对路径, 绝对路径保持不变)
-     * @param path 文件路径
-     * @param env 环境 必须以 / 结尾
-     * @param need_free 是否需要释放 path
-     */
-    std::string findPath(const std::string &path, const std::string &env){
-#ifdef __linux
-        if (path[0] != SEP_CH) // 不以 / 开头
-#else
-        if (!(isupper(path[0]) && (path)[1] == ':'))  // 不以盘符开头
-#endif
-            return env + path;  // 调整为相对路径模式
-        return path;
-    }
-
-    /**
-     * 获取可执行程序目录
-     * @param dep 从可执行程序往回跳出的层数
-     */
-    std::string getHomePath() {
-        aFun_path exe_path[218] = {0};
-#ifdef aFunWIN32_NO_CYGWIN
-        DWORD ret = GetModuleFileNameW(nullptr, exe_path, 217);  // 预留一位给NUL
-        if (ret == 0 || wcslen(exe_path) == 0)
-            return "";
-        char *path = nullptr;
-        if (convertFromWideByte(&path, exe_path, CP_UTF8) == 0)
-            return "";
-        std::string re = getFilePath(path, 2);
-        safeFree(path);
-        return re;
-#else
-        ssize_t ret =  readlink("/proc/self/exe", exe_path, 217);  // 预留一位给NUL
-        if (ret == -1 || strlen(exe_path) == 0)
-            return "";
-        return getFilePath(exe_path, 2);
-#endif
-    }
-
-    /**
-     * 获取可执行程序目录
-     * @param dep 从可执行程序往回跳出的层数
-     */
-    std::string getExePath() {
-        aFun_path exe_path[218] = {0};
-#ifdef aFunWIN32_NO_CYGWIN
-        DWORD ret = GetModuleFileNameW(nullptr, exe_path, 217);  // 预留一位给NUL
-        if (ret == 0 || wcslen(exe_path) == 0)
-            return "";
-        char *path = nullptr;
-        if (convertFromWideByte(&path, exe_path, CP_UTF8) == 0)
-            return "";
-        std::string re = path;
-        safeFree(path);
-        return re;
-#else
-        ssize_t ret =  readlink("/proc/self/exe", exe_path, 217);  // 预留一位给NUL
-        if (ret == -1 || strlen(exe_path) == 0)
-            return "";
-        return exe_path;
-#endif
-    }
-
     /**
      * @param path 文件路径 (utf-8)
      * @return 文件大小
@@ -255,45 +89,6 @@ namespace aFuntool {
         return (uintmax_t)stat.st_size;  // 返回文件大小
     }
 
-    /**
-     * 检查给定字符串是否utf-8编码
-     * @param str 字符串
-     */
-    bool isCharUTF8(const char *str) {
-        int code = 0;  // utf-8 多字节数
-        for (const char *ch = str; *ch != NUL; ch++) {
-            unsigned char c = *ch;
-            unsigned char c_ = ~c;
-
-            assertFatalErrorLog(code >= 0 && code <= 5, aFunSysLogger, 2, "str = %s", str);
-            if (code == 0) {
-                if ((c_ & 0xFC) == 0 && (c & 0x02) == 0)  // 检查是否为1111110x, 先对其取反, 使用0xFC掩码检查前6位是否为0, 然后单独检查倒数第二位是否为0
-                    code = 5;  // 剩余 5 个字节
-                else if ((c_ & 0xF8) == 0 && (c & 0x04) == 0)
-                    code = 4;  // 剩余 4 个字节
-                else if ((c_ & 0xF0) == 0 && (c & 0x08) == 0)
-                    code = 3;  // 剩余 3 个字节
-                else if ((c_ & 0xE0) == 0 && (c & 0x10) == 0)
-                    code = 2;  // 剩余 2 个字节
-                else if ((c_ & 0xC0) == 0 && (c & 0x20) == 0)
-                    code = 1;  // 剩余 1 个字节
-                else if ((c & 0x80) == 0)  // 检查最高位是否为0
-                    code = 0;
-                else
-                    return false;
-            } else if ((c_ & 0x80) == 0 && (c & 0x40) == 0)
-                code--;
-            else
-                return false;
-        }
-
-        return true;
-    }
-
-    bool isCharUTF8(const std::string &str) {
-        return isCharUTF8(str.c_str());
-    }
-
     /**
      * 打开指定文件
      * @param path_ 路径 (utf-8)

+ 5 - 7
src/tool/log.cpp

@@ -14,7 +14,6 @@
 #include <cstdio>
 #include <cstdlib>
 #include <cstdarg>
-#include <cstring>
 #include "tool-type.h"
 #include "log.h"
 #include "tool-exception.h"
@@ -128,9 +127,8 @@ namespace aFuntool {
         csv_ = nullptr;
     }
 
-
-/* LogLevel和字符串的转换 */
-    const char *LogLevelName[] = {
+    static const char *LogLevelName[] = {
+            /* LogLevel和字符串的转换 */
             "TK",  // track 0
             "DE",  // debug 1
             "IN",  // info 2
@@ -140,7 +138,7 @@ namespace aFuntool {
             "FE",  // fatal_error 6
     };
 
-    const char *LogLevelNameLong[] = {
+    static const char *LogLevelNameLong[] = {
             /* 内容输出到终端时使用*/
             "Track",  // track 0
             "Debug",  // debug 1
@@ -201,11 +199,11 @@ namespace aFuntool {
                                   const char *file, int line,
                                   const char *info){
         if (level < log_warning) {
-            cout << "\r* " << LogLevelName[level] << "/[" << id << "] " << tid;
+            cout << "\r* " << LogLevelNameLong[level] << "/[" << id << "] " << tid;
             cout << " " << t << " " << ti << " (" << file << ":" << line << ") : '" << info << "'\n";
             fflush(stdout);
         } else {
-            cerr << "\r* " << LogLevelName[level] << "/[" << id << "] " << tid;
+            cerr << "\r* " << LogLevelNameLong[level] << "/[" << id << "] " << tid;
             cerr << " " << t << " " << ti << " (" << file << ":" << line << ") : '" << info << "'\n";
             fflush(stderr);
         }

+ 1 - 1
src/tool/regex.cpp

@@ -1,6 +1,6 @@
 #include "tool-exception.h"
 #include "tool-regex.h"
-#include "file.h"
+#include "encoding.h"
 #include "string"
 
 namespace aFuntool {

+ 3 - 9
test/src/core-init.cpp

@@ -3,20 +3,14 @@ using namespace aFuncore;
 using namespace aFuntool;
 
 int main() {
-    std::string base_path = getHomePath();
-    if (base_path.empty()) {
-        printf_stderr(0, "aFunlang init error.");
-        aFunExit(EXIT_FAILURE);
-    }
-
-    auto factor = aFuntool::LogFactory(base_path + aFuntool::SEP + "aFunlog", true);
+    auto factor = aFuntool::LogFactory(std::string(".") + aFuntool::SEP + "aFunlog", true);
     auto core_logger = aFuntool::Logger(factor, "aFun-core");
     auto sys_logger = aFuntool::Logger(factor, "aFun-sys");
-    aFuncore::InitInfo info {base_path, factor, core_logger, sys_logger};
+    auto info = aFuncore::InitInfo(factor, core_logger, sys_logger);
 
     if (!aFunCoreInit(&info)) {
         printf_stderr(0, "aFunlang init error.");
-        aFunExit(EXIT_FAILURE);
+        aFunExitReal(EXIT_FAILURE);
     }
     return 0;
 }

+ 3 - 9
test/src/it-init.cpp

@@ -3,21 +3,15 @@ using namespace aFuncore;
 using namespace aFuntool;
 
 int main() {
-    std::string base_path = getHomePath();
-    if (base_path.empty()) {
-        printf_stderr(0, "aFunlang init error.");
-        aFunExit(EXIT_FAILURE);
-    }
-
-    auto factor = aFuntool::LogFactory(base_path + aFuntool::SEP + "aFunlog", true);
+    auto factor = aFuntool::LogFactory(std::string(".") + aFuntool::SEP + "aFunlog", true);
     auto core_logger = aFuntool::Logger(factor, "aFun-core");
     auto sys_logger = aFuntool::Logger(factor, "aFun-sys");
     auto aFun_logger = aFuntool::Logger(factor, "aFun");
-    aFunit::aFunInitInfo info {base_path, factor, aFun_logger, core_logger, sys_logger};
+    auto info = aFunit::aFunInitInfo(factor, aFun_logger, core_logger, sys_logger);
 
     if (!aFunInit(&info)) {
         printf_stderr(0, "aFunlang init error.");
-        aFunExit(EXIT_FAILURE);
+        aFunExitReal(EXIT_FAILURE);
     }
     return 0;
 }

+ 2 - 8
test/src/run-code.cpp

@@ -299,16 +299,10 @@ int Main() {
 int main() {
     int exit_code = 0;
     try {
-        std::string base_path = getHomePath();
-        if (base_path.empty()) {
-            printf_stderr(0, "aFunlang init error.");
-            aFunExitReal(EXIT_FAILURE);
-        }
-
-        auto factor = aFuntool::LogFactory(base_path + aFuntool::SEP + "aFunlog", true);
+        auto factor = aFuntool::LogFactory(std::string(".") + aFuntool::SEP + "aFunlog", true);
         auto core_logger = aFuntool::Logger(factor, "aFun-core");
         auto sys_logger = aFuntool::Logger(factor, "aFun-sys");
-        aFuncore::InitInfo info {base_path, factor, core_logger, sys_logger};
+        auto info = aFuncore::InitInfo(factor, core_logger, sys_logger);
 
         if (!aFunCoreInit(&info)) {
             printf_stderr(0, "aFunlang init error.");

+ 1 - 7
test/src/tool-logger.cpp

@@ -4,15 +4,9 @@ using namespace aFuntool;
 int main(){
     int exit_code = 0;
     try {
-        std::string base_path = getHomePath();
-        if (base_path.empty()) {
-            printf("Not Exe Dir\n");
-            aFunExit(0);
-        }
-
         setlocale(LC_ALL, "");
 
-        auto factor = LogFactory(base_path + SEP + "aFunlog", true);
+        auto factor = LogFactory(std::string(".") + SEP + "aFunlog", true);
         auto logger = Logger(factor, "Test", aFuntool::log_info);
         infoLog(&logger, "Test logger");
         aFunExit(0);