mirror of
https://github.com/Karaka-Management/cOMS.git
synced 2026-02-16 18:28:42 +00:00
Update code style
This commit is contained in:
parent
b34004c1cb
commit
33b480fbae
|
|
@ -17,9 +17,7 @@
|
||||||
#include "../DatabaseType.h"
|
#include "../DatabaseType.h"
|
||||||
#include "../DatabaseStatus.h"
|
#include "../DatabaseStatus.h"
|
||||||
|
|
||||||
namespace DataStorage
|
namespace DataStorage::Database
|
||||||
{
|
|
||||||
namespace Database
|
|
||||||
{
|
{
|
||||||
typedef struct {
|
typedef struct {
|
||||||
size_t rows = 0;
|
size_t rows = 0;
|
||||||
|
|
@ -57,6 +55,5 @@ namespace DataStorage
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -21,9 +21,7 @@
|
||||||
#include "PostgresqlConnection.h"
|
#include "PostgresqlConnection.h"
|
||||||
#include "SQLiteConnection.h"
|
#include "SQLiteConnection.h"
|
||||||
|
|
||||||
namespace DataStorage
|
namespace DataStorage::Database
|
||||||
{
|
|
||||||
namespace Database
|
|
||||||
{
|
{
|
||||||
ConnectionAbstract *create_connection(DbConnectionConfig dbdata)
|
ConnectionAbstract *create_connection(DbConnectionConfig dbdata)
|
||||||
{
|
{
|
||||||
|
|
@ -57,6 +55,5 @@ namespace DataStorage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -15,9 +15,7 @@
|
||||||
|
|
||||||
#include "../DatabaseType.h"
|
#include "../DatabaseType.h"
|
||||||
|
|
||||||
namespace DataStorage
|
namespace DataStorage::Database
|
||||||
{
|
|
||||||
namespace Database
|
|
||||||
{
|
{
|
||||||
typedef struct {
|
typedef struct {
|
||||||
DatabaseType db = DatabaseType::UNDEFINED;
|
DatabaseType db = DatabaseType::UNDEFINED;
|
||||||
|
|
@ -56,6 +54,5 @@ namespace DataStorage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -20,9 +20,7 @@
|
||||||
#include "../DatabaseType.h"
|
#include "../DatabaseType.h"
|
||||||
#include "../DatabaseStatus.h"
|
#include "../DatabaseStatus.h"
|
||||||
|
|
||||||
namespace DataStorage
|
namespace DataStorage::Database
|
||||||
{
|
|
||||||
namespace Database
|
|
||||||
{
|
{
|
||||||
struct MysqlConnection : ConnectionAbstract {
|
struct MysqlConnection : ConnectionAbstract {
|
||||||
MysqlConnection(DbConnectionConfig dbdata)
|
MysqlConnection(DbConnectionConfig dbdata)
|
||||||
|
|
@ -145,6 +143,5 @@ namespace DataStorage
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -20,9 +20,7 @@
|
||||||
#include "../DatabaseType.h"
|
#include "../DatabaseType.h"
|
||||||
#include "../DatabaseStatus.h"
|
#include "../DatabaseStatus.h"
|
||||||
|
|
||||||
namespace DataStorage
|
namespace DataStorage::Database
|
||||||
{
|
|
||||||
namespace Database
|
|
||||||
{
|
{
|
||||||
struct PostgresqlConnection : ConnectionAbstract {
|
struct PostgresqlConnection : ConnectionAbstract {
|
||||||
PostgresqlConnection(DbConnectionConfig dbdata)
|
PostgresqlConnection(DbConnectionConfig dbdata)
|
||||||
|
|
@ -139,6 +137,5 @@ namespace DataStorage
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -20,9 +20,7 @@
|
||||||
#include "../DatabaseType.h"
|
#include "../DatabaseType.h"
|
||||||
#include "../DatabaseStatus.h"
|
#include "../DatabaseStatus.h"
|
||||||
|
|
||||||
namespace DataStorage
|
namespace DataStorage::Database
|
||||||
{
|
|
||||||
namespace Database
|
|
||||||
{
|
{
|
||||||
struct SQLiteConnection : ConnectionAbstract {
|
struct SQLiteConnection : ConnectionAbstract {
|
||||||
SQLiteConnection(DbConnectionConfig dbdata)
|
SQLiteConnection(DbConnectionConfig dbdata)
|
||||||
|
|
@ -156,6 +154,5 @@ namespace DataStorage
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -10,9 +10,7 @@
|
||||||
#ifndef DATASTORAGE_DATABASE_STATUS_H
|
#ifndef DATASTORAGE_DATABASE_STATUS_H
|
||||||
#define DATASTORAGE_DATABASE_STATUS_H
|
#define DATASTORAGE_DATABASE_STATUS_H
|
||||||
|
|
||||||
namespace DataStorage
|
namespace DataStorage::Database
|
||||||
{
|
|
||||||
namespace Database
|
|
||||||
{
|
{
|
||||||
typedef enum {
|
typedef enum {
|
||||||
OK = 0,
|
OK = 0,
|
||||||
|
|
@ -23,6 +21,5 @@ namespace DataStorage
|
||||||
CLOSED = 5
|
CLOSED = 5
|
||||||
} DatabaseStatus;
|
} DatabaseStatus;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -12,9 +12,7 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
namespace DataStorage
|
namespace DataStorage::Database
|
||||||
{
|
|
||||||
namespace Database
|
|
||||||
{
|
{
|
||||||
typedef enum {
|
typedef enum {
|
||||||
MYSQL = 1,
|
MYSQL = 1,
|
||||||
|
|
@ -39,6 +37,5 @@ namespace DataStorage
|
||||||
return DatabaseType::UNDEFINED;
|
return DatabaseType::UNDEFINED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -18,9 +18,7 @@
|
||||||
#include "ReadMapper.h"
|
#include "ReadMapper.h"
|
||||||
#include "MapperAbstract.h"
|
#include "MapperAbstract.h"
|
||||||
|
|
||||||
namespace DataStorage
|
namespace DataStorage::Database
|
||||||
{
|
|
||||||
namespace Database
|
|
||||||
{
|
{
|
||||||
static DataStorage::Database::ConnectionAbstract *db;
|
static DataStorage::Database::ConnectionAbstract *db;
|
||||||
static const char *dateTimeFormat = "Y-m-d H:i:s";
|
static const char *dateTimeFormat = "Y-m-d H:i:s";
|
||||||
|
|
@ -54,6 +52,5 @@ namespace DataStorage
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
namespace DataStorage
|
namespace DataStorage::Database
|
||||||
{
|
|
||||||
namespace Database
|
|
||||||
{
|
{
|
||||||
typedef enum {
|
typedef enum {
|
||||||
MAPPER_DEFAULT = 0,
|
MAPPER_DEFAULT = 0,
|
||||||
|
|
@ -217,6 +215,5 @@ namespace DataStorage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -12,13 +12,12 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "../Connection/ConnectionAbstract.h"
|
#include "../Connection/ConnectionAbstract.h"
|
||||||
#include "DataMapperTypes.h"
|
#include "DataMapperTypes.h"
|
||||||
|
|
||||||
namespace DataStorage
|
namespace DataStorage::Database
|
||||||
{
|
|
||||||
namespace Database
|
|
||||||
{
|
{
|
||||||
struct MapperAbstract {
|
struct MapperAbstract {
|
||||||
const DataStorage::Database::MapperData *mapper = NULL;
|
const DataStorage::Database::MapperData *mapper = NULL;
|
||||||
|
|
@ -102,6 +101,5 @@ namespace DataStorage
|
||||||
virtual void *execute(void *options = NULL);
|
virtual void *execute(void *options = NULL);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,7 @@
|
||||||
#include "DataMapperFactory.h"
|
#include "DataMapperFactory.h"
|
||||||
#include "MapperAbstract.h"
|
#include "MapperAbstract.h"
|
||||||
|
|
||||||
namespace DataStorage
|
namespace DataStorage::Database
|
||||||
{
|
|
||||||
namespace Database
|
|
||||||
{
|
{
|
||||||
struct ReadMapper : MapperAbstract {
|
struct ReadMapper : MapperAbstract {
|
||||||
ReadMapper *get()
|
ReadMapper *get()
|
||||||
|
|
@ -65,6 +63,5 @@ namespace DataStorage
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
namespace DataStorage
|
namespace DataStorage::Database
|
||||||
{
|
|
||||||
namespace Database
|
|
||||||
{
|
{
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *name;
|
char *name;
|
||||||
|
|
@ -57,6 +55,5 @@ namespace DataStorage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -15,9 +15,7 @@
|
||||||
|
|
||||||
#include "DbField.h"
|
#include "DbField.h"
|
||||||
|
|
||||||
namespace DataStorage
|
namespace DataStorage::Database
|
||||||
{
|
|
||||||
namespace Database
|
|
||||||
{
|
{
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *name;
|
char *name;
|
||||||
|
|
@ -42,6 +40,5 @@ namespace DataStorage
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
#define HASH_MD5_H
|
#define HASH_MD5_H
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
// https://www.rfc-editor.org/rfc/rfc1321
|
// https://www.rfc-editor.org/rfc/rfc1321
|
||||||
|
|
||||||
|
|
@ -37,7 +39,7 @@ namespace Hash {
|
||||||
uint32_t a, b, c, d;
|
uint32_t a, b, c, d;
|
||||||
uint32_t aa, bb, cc, dd;
|
uint32_t aa, bb, cc, dd;
|
||||||
|
|
||||||
ptr = data;
|
ptr = (const unsigned char *) data;
|
||||||
|
|
||||||
a = ctx->a;
|
a = ctx->a;
|
||||||
b = ctx->b;
|
b = ctx->b;
|
||||||
|
|
|
||||||
|
|
@ -116,6 +116,7 @@
|
||||||
#define HASH_MEOW_H
|
#define HASH_MEOW_H
|
||||||
|
|
||||||
// #include <immintrin.h>
|
// #include <immintrin.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#if !defined(meow_u8)
|
#if !defined(meow_u8)
|
||||||
#define MEOW_HASH_VERSION 5
|
#define MEOW_HASH_VERSION 5
|
||||||
|
|
@ -199,9 +200,7 @@
|
||||||
pxor(r2, r3)
|
pxor(r2, r3)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Hash
|
namespace Hash::Meow
|
||||||
{
|
|
||||||
namespace Meow
|
|
||||||
{
|
{
|
||||||
#if MEOW_DUMP
|
#if MEOW_DUMP
|
||||||
struct meow_dump
|
struct meow_dump
|
||||||
|
|
@ -740,7 +739,6 @@ namespace Hash
|
||||||
return (const char *) str;
|
return (const char *) str;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#undef INSTRUCTION_REORDER_BARRIER
|
#undef INSTRUCTION_REORDER_BARRIER
|
||||||
#undef prefetcht0
|
#undef prefetcht0
|
||||||
|
|
|
||||||
|
|
@ -200,7 +200,7 @@ void sha_256_write(struct Sha_256 *sha_256, const void *data, size_t len)
|
||||||
{
|
{
|
||||||
sha_256->total_len += len;
|
sha_256->total_len += len;
|
||||||
|
|
||||||
const uint8_t *p = data;
|
const uint8_t *p = (uint8_t *) data;
|
||||||
|
|
||||||
while (len > 0) {
|
while (len > 0) {
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,7 @@
|
||||||
#include <opencv2/opencv.hpp>
|
#include <opencv2/opencv.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace Image
|
namespace Image::BillDetection
|
||||||
{
|
|
||||||
namespace BillDetection
|
|
||||||
{
|
{
|
||||||
cv::Mat highlightBill(cv::Mat in)
|
cv::Mat highlightBill(cv::Mat in)
|
||||||
{
|
{
|
||||||
|
|
@ -76,6 +74,5 @@ namespace Image
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -13,9 +13,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
namespace Image
|
namespace Image::ImageUtils
|
||||||
{
|
|
||||||
namespace ImageUtils
|
|
||||||
{
|
{
|
||||||
inline
|
inline
|
||||||
float lightnessFromRgb(int r, int g, int b)
|
float lightnessFromRgb(int r, int g, int b)
|
||||||
|
|
@ -33,17 +31,6 @@ namespace Image
|
||||||
|
|
||||||
return lStar / 100.0;
|
return lStar / 100.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
|
||||||
int rgbToInt(int r, int g, int b)
|
|
||||||
{
|
|
||||||
int rgb = r;
|
|
||||||
rgb = (rgb << 8) + g;
|
|
||||||
rgb = (rgb << 8) + b;
|
|
||||||
|
|
||||||
return rgb;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
#include "ImageUtils.h"
|
#include "ImageUtils.h"
|
||||||
#include "../Utils/MathUtils.h"
|
#include "../Utils/MathUtils.h"
|
||||||
|
|
||||||
namespace Image
|
namespace Image::Kernel
|
||||||
{
|
{
|
||||||
const float KERNEL_RIDGE_1[3][3] = {
|
const float KERNEL_RIDGE_1[3][3] = {
|
||||||
{0.0, -1.0, 0.0},
|
{0.0, -1.0, 0.0},
|
||||||
|
|
@ -62,8 +62,6 @@ namespace Image
|
||||||
{-1.0 / 256.0, -4.0 / 256.0, -6.0 / 256.0, -4.0 / 256.0, -1.0 / 256.0},
|
{-1.0 / 256.0, -4.0 / 256.0, -6.0 / 256.0, -4.0 / 256.0, -1.0 / 256.0},
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace Kernel
|
|
||||||
{
|
|
||||||
inline
|
inline
|
||||||
cv::Mat convolve(cv::Mat in, const float kernel[][3])
|
cv::Mat convolve(cv::Mat in, const float kernel[][3])
|
||||||
{
|
{
|
||||||
|
|
@ -76,6 +74,5 @@ namespace Image
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -16,9 +16,7 @@
|
||||||
|
|
||||||
#include "../Utils/MathUtils.h"
|
#include "../Utils/MathUtils.h"
|
||||||
|
|
||||||
namespace Image
|
namespace Image::Skew
|
||||||
{
|
|
||||||
namespace Skew
|
|
||||||
{
|
{
|
||||||
cv::Mat deskewHoughLines(cv::Mat in, int maxDegree = 45)
|
cv::Mat deskewHoughLines(cv::Mat in, int maxDegree = 45)
|
||||||
{
|
{
|
||||||
|
|
@ -88,6 +86,5 @@ namespace Image
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -16,9 +16,7 @@
|
||||||
#include "ImageUtils.h"
|
#include "ImageUtils.h"
|
||||||
#include "../Utils/MathUtils.h"
|
#include "../Utils/MathUtils.h"
|
||||||
|
|
||||||
namespace Image
|
namespace Image::Thresholding
|
||||||
{
|
|
||||||
namespace Thresholding
|
|
||||||
{
|
{
|
||||||
cv::Mat integralThresholding(cv::Mat in)
|
cv::Mat integralThresholding(cv::Mat in)
|
||||||
{
|
{
|
||||||
|
|
@ -76,6 +74,5 @@ namespace Image
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -16,9 +16,7 @@
|
||||||
|
|
||||||
#include "../Hash/MeowHash.h"
|
#include "../Hash/MeowHash.h"
|
||||||
|
|
||||||
namespace Stdlib
|
namespace Stdlib::HashTable
|
||||||
{
|
|
||||||
namespace HashTable
|
|
||||||
{
|
{
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char *key;
|
const char *key;
|
||||||
|
|
@ -216,6 +214,5 @@ namespace Stdlib
|
||||||
free(table->entries);
|
free(table->entries);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -48,9 +48,7 @@ namespace Utils
|
||||||
|
|
||||||
if (pos != NULL) {
|
if (pos != NULL) {
|
||||||
memcpy(dir, arg, (pos - arg) * sizeof(char));
|
memcpy(dir, arg, (pos - arg) * sizeof(char));
|
||||||
|
|
||||||
chdir(dir);
|
chdir(dir);
|
||||||
|
|
||||||
free(dir);
|
free(dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,9 +13,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
namespace Utils
|
namespace Utils::ArraySort
|
||||||
{
|
|
||||||
namespace ArraySort
|
|
||||||
{
|
{
|
||||||
inline
|
inline
|
||||||
void reverse_int(int64_t *arr, size_t size)
|
void reverse_int(int64_t *arr, size_t size)
|
||||||
|
|
@ -57,6 +55,5 @@ namespace Utils
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -16,9 +16,7 @@
|
||||||
|
|
||||||
#include "StringUtils.h"
|
#include "StringUtils.h"
|
||||||
|
|
||||||
namespace Utils
|
namespace Utils::ArrayUtils
|
||||||
{
|
|
||||||
namespace ArrayUtils
|
|
||||||
{
|
{
|
||||||
inline
|
inline
|
||||||
char* get_arg(const char *id, char **argv, size_t size)
|
char* get_arg(const char *id, char **argv, size_t size)
|
||||||
|
|
@ -194,18 +192,17 @@ namespace Utils
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < size1; ++i) {
|
for (size_t i = 0; i < size1; ++i) {
|
||||||
merged[i] = (char*) malloc((strlen(arr1[i]) + 1) * sizeof(char));
|
merged[i] = (char*) malloc((strlen(array1[i]) + 1) * sizeof(char));
|
||||||
strcpy(merged[i], arr1[i]);
|
strcpy(merged[i], array1[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < size2; ++i) {
|
for (size_t i = 0; i < size2; ++i) {
|
||||||
merged[i] = (char*) malloc((strlen(arr2[i]) + 1) * sizeof(char));
|
merged[i] = (char*) malloc((strlen(array2[i]) + 1) * sizeof(char));
|
||||||
strcpy(merged[i], arr2[i]);
|
strcpy(merged[i], array2[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return merged;
|
return merged;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
57
Utils/ColorUtils.h
Normal file
57
Utils/ColorUtils.h
Normal file
|
|
@ -0,0 +1,57 @@
|
||||||
|
/**
|
||||||
|
* Karaka
|
||||||
|
*
|
||||||
|
* @package Utils
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 1.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link https://jingga.app
|
||||||
|
*/
|
||||||
|
#ifndef UTILS_STRING_UTILS_H
|
||||||
|
#define UTILS_STRING_UTILS_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
namespace Utils::ColorUtils
|
||||||
|
{
|
||||||
|
typedef struct {
|
||||||
|
char r = 0;
|
||||||
|
char g = 0;
|
||||||
|
char b = 0;
|
||||||
|
} RGB;
|
||||||
|
|
||||||
|
inline
|
||||||
|
RGB* int_to_rgb(int rgb)
|
||||||
|
{
|
||||||
|
RGB* result = (RGB*) malloc(1 * sizeof(RGB));
|
||||||
|
|
||||||
|
result->r = rgb & 255;
|
||||||
|
result->g = (rgb >> 8) & 255;
|
||||||
|
result->b = (rgb >> 16) & 255;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
int rgb_to_int(RGB* rgb)
|
||||||
|
{
|
||||||
|
int i = (255 & rgb->r) << 16;
|
||||||
|
i += (255 & rgb->g) << 8;
|
||||||
|
i += (255 & rgb->b);
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
int rgb_to_int(char r, char g, char b)
|
||||||
|
{
|
||||||
|
int i = (255 & r) << 16;
|
||||||
|
i += (255 & g) << 8;
|
||||||
|
i += (255 & b);
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
@ -23,9 +23,7 @@
|
||||||
|
|
||||||
#include "OSWrapper.h"
|
#include "OSWrapper.h"
|
||||||
|
|
||||||
namespace Utils
|
namespace Utils::FileUtils
|
||||||
{
|
|
||||||
namespace FileUtils
|
|
||||||
{
|
{
|
||||||
inline
|
inline
|
||||||
bool file_exists (const char *filename)
|
bool file_exists (const char *filename)
|
||||||
|
|
@ -129,6 +127,5 @@ namespace Utils
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -14,11 +14,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
namespace Utils
|
namespace Utils::Rng::StringUtils
|
||||||
{
|
|
||||||
namespace Rng
|
|
||||||
{
|
|
||||||
namespace StringUtils
|
|
||||||
{
|
{
|
||||||
inline
|
inline
|
||||||
char* generate_string(
|
char* generate_string(
|
||||||
|
|
@ -39,5 +35,5 @@ namespace Utils
|
||||||
return randomString;
|
return randomString;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
#endif
|
||||||
|
|
@ -17,9 +17,7 @@
|
||||||
#include "MathUtils.h"
|
#include "MathUtils.h"
|
||||||
#include "ArraySort.h"
|
#include "ArraySort.h"
|
||||||
|
|
||||||
namespace Utils
|
namespace Utils::StringUtils
|
||||||
{
|
|
||||||
namespace StringUtils
|
|
||||||
{
|
{
|
||||||
inline
|
inline
|
||||||
char *search_replace(const char *haystack, const char *needle, const char *replace)
|
char *search_replace(const char *haystack, const char *needle, const char *replace)
|
||||||
|
|
@ -97,6 +95,7 @@ namespace Utils
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
char *strsep(char **sp, char *sep)
|
char *strsep(char **sp, char *sep)
|
||||||
{
|
{
|
||||||
char *p, *s;
|
char *p, *s;
|
||||||
|
|
@ -117,6 +116,8 @@ namespace Utils
|
||||||
return(s);
|
return(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @todo Implement delim as const char* (also allow \0 length)
|
||||||
|
inline
|
||||||
int str_split(char **list, char *str, const char delim)
|
int str_split(char **list, char *str, const char delim)
|
||||||
{
|
{
|
||||||
size_t splits = str_count(str, (char *) &delim) + 1;
|
size_t splits = str_count(str, (char *) &delim) + 1;
|
||||||
|
|
@ -135,16 +136,47 @@ namespace Utils
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @todo Implement delim as const char* (also allow \0 length)
|
||||||
|
inline
|
||||||
|
char* str_combine(char **str, size_t size, const char delim)
|
||||||
|
{
|
||||||
|
if (size < 1) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t total_size = 0;
|
||||||
|
for (size_t i = 0; i < size; ++i) {
|
||||||
|
total_size += strlen(str[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If delim ever becomes a string replace * 1 with * strlen(delimiter)
|
||||||
|
total_size += (size - 1) * 1 + 1;
|
||||||
|
|
||||||
|
char *result = (char *) malloc(total_size * sizeof(char));
|
||||||
|
if (!result) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
strcpy(result, str[0]);
|
||||||
|
|
||||||
|
for (size_t i = 0; i < size; ++i) {
|
||||||
|
strcat(result, &delim);
|
||||||
|
strcat(result, str[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char **values;
|
char **values;
|
||||||
int *masks;
|
int64_t *masks;
|
||||||
int size;
|
size_t size;
|
||||||
} text_diff;
|
} text_diff;
|
||||||
|
|
||||||
text_diff computeLCSDiff(char **from, int fromSize, char **to, int toSize)
|
text_diff computeLCSDiff(char **from, int fromSize, char **to, int toSize)
|
||||||
{
|
{
|
||||||
char **diffValues = (char **) malloc(fromSize * toSize * sizeof(char *));
|
char **diffValues = (char **) malloc(fromSize * toSize * sizeof(char *));
|
||||||
int *diffMasks = (int *) calloc(fromSize * toSize, sizeof(int));
|
int64_t *diffMasks = (int64_t *) calloc(fromSize * toSize, sizeof(int64_t));
|
||||||
|
|
||||||
int *dm = (int *) calloc((fromSize + 1) * (toSize + 1), sizeof(int));
|
int *dm = (int *) calloc((fromSize + 1) * (toSize + 1), sizeof(int));
|
||||||
|
|
||||||
|
|
@ -173,7 +205,7 @@ namespace Utils
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int diffIndex = 0;
|
size_t diffIndex = 0;
|
||||||
|
|
||||||
i = fromSize;
|
i = fromSize;
|
||||||
j = toSize;
|
j = toSize;
|
||||||
|
|
@ -254,7 +286,7 @@ namespace Utils
|
||||||
}
|
}
|
||||||
diffValues = diffValuesT;
|
diffValues = diffValuesT;
|
||||||
|
|
||||||
int *diffMasksT = (int *) realloc(diffMasks, diffIndex * sizeof(int));
|
int64_t *diffMasksT = (int64_t *) realloc(diffMasks, diffIndex * sizeof(int64_t));
|
||||||
if (!diffMasksT) {
|
if (!diffMasksT) {
|
||||||
free(diffMasks);
|
free(diffMasks);
|
||||||
}
|
}
|
||||||
|
|
@ -272,6 +304,5 @@ namespace Utils
|
||||||
return text_diff{diffValues, diffMasks, diffIndex};
|
return text_diff{diffValues, diffMasks, diffIndex};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -23,9 +23,7 @@
|
||||||
|
|
||||||
#include "FileUtils.h"
|
#include "FileUtils.h"
|
||||||
|
|
||||||
namespace Utils
|
namespace Utils::WebUtils
|
||||||
{
|
|
||||||
namespace WebUtils
|
|
||||||
{
|
{
|
||||||
static bool CURL_SETUP = false;
|
static bool CURL_SETUP = false;
|
||||||
|
|
||||||
|
|
@ -294,6 +292,5 @@ namespace Utils
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Loading…
Reference in New Issue
Block a user