some code moved to String directory
This commit is contained in:
parent
5fd395d7eb
commit
2434a126da
@ -1,24 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "Autoarr.h"
|
||||
|
||||
typedef Autoarr(int8) StringBuilder;
|
||||
|
||||
StringBuilder* StringBuilder_create(uint16 max_blocks_count, uint16 max_block_length);
|
||||
void StringBuilder_free(StringBuilder* b);
|
||||
void StringBuilder_pop(StringBuilder* b);
|
||||
void StringBuilder_append_char(StringBuilder* b, char c);
|
||||
void StringBuilder_append_cptr(StringBuilder* b, char* s);
|
||||
void StringBuilder_append_string(StringBuilder* b, string s);
|
||||
void StringBuilder_append_int64(StringBuilder* b, int64 a);
|
||||
void StringBuilder_append_uint64(StringBuilder* b, uint64 a);
|
||||
void StringBuilder_append_double(StringBuilder* b, double a);
|
||||
char* StringBuilder_build(StringBuilder* b);
|
||||
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
@ -1,5 +1,5 @@
|
||||
#include "DtsodV24.h"
|
||||
#include "../Autoarr/StringBuilder.h"
|
||||
#include "../String/StringBuilder.h"
|
||||
|
||||
#define ARR_BC 64
|
||||
#define ARR_BL 1024
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#include "DtsodV24.h"
|
||||
#include "../Autoarr/StringBuilder.h"
|
||||
#include "../String/StringBuilder.h"
|
||||
|
||||
// 65536 max length!
|
||||
#define STRB_BC 64
|
||||
|
||||
25
String/StringBuilder.h
Normal file
25
String/StringBuilder.h
Normal file
@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "../Autoarr/Autoarr.h"
|
||||
#include "../String/string.h"
|
||||
|
||||
typedef Autoarr(int8) StringBuilder;
|
||||
|
||||
StringBuilder* StringBuilder_create(uint16 max_blocks_count, uint16 max_block_length);
|
||||
void StringBuilder_free(StringBuilder* b);
|
||||
void StringBuilder_pop(StringBuilder* b);
|
||||
void StringBuilder_append_char(StringBuilder* b, char c);
|
||||
void StringBuilder_append_cptr(StringBuilder* b, char* s);
|
||||
void StringBuilder_append_string(StringBuilder* b, string s);
|
||||
void StringBuilder_append_int64(StringBuilder* b, int64 a);
|
||||
void StringBuilder_append_uint64(StringBuilder* b, uint64 a);
|
||||
void StringBuilder_append_double(StringBuilder* b, double a);
|
||||
char* StringBuilder_build(StringBuilder* b);
|
||||
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
@ -1,39 +1,4 @@
|
||||
#include "base.h"
|
||||
|
||||
// returns length of string (including \0)
|
||||
uint32 cptr_length(char* str){
|
||||
uint32 len=0;
|
||||
while(*(str++)) len++;
|
||||
return ++len;
|
||||
}
|
||||
|
||||
// allocates new char[] and copies src there
|
||||
char* cptr_copy(char* src){
|
||||
uint32 len=cptr_length(src);
|
||||
char* dst=malloc(len*sizeof(char));
|
||||
while(len-->0)
|
||||
dst[len]=src[len];
|
||||
return dst;
|
||||
}
|
||||
|
||||
// compares two char buffers, NullPtr-friendly
|
||||
bool cptr_compare(char* key0, char* key1){
|
||||
if(!key0) return key1 ? false : true;
|
||||
if(!key1) return false;
|
||||
while(*key0&&*key1)
|
||||
if(*key0++ != *key1++)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// multiplies char n times
|
||||
char* char_multiply(char c, uint32 n){
|
||||
char* rez=malloc(n+1);
|
||||
rez[n]=0;
|
||||
while(n-->0)
|
||||
rez[n]=c;
|
||||
return rez;
|
||||
}
|
||||
#include "../String/string.h"
|
||||
|
||||
// copies str content to new char pointer value (adding '\0' at the end)
|
||||
char* string_cpToCptr(string str){
|
||||
@ -4,19 +4,7 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "types.h"
|
||||
|
||||
// returns length of string (including \0)
|
||||
uint32 cptr_length(char* str);
|
||||
|
||||
// allocates new char[] and copies src there
|
||||
char* cptr_copy(char* src);
|
||||
|
||||
// compares two char buffers, NullPtr-friendly
|
||||
bool cptr_compare(char* key0, char* key1);
|
||||
|
||||
// multiplies char n times
|
||||
char* char_multiply(char c, uint32 n);
|
||||
#include "../base/base.h"
|
||||
|
||||
// my fixed length string struct
|
||||
// doesn't store '\0' at the end
|
||||
@ -7,7 +7,7 @@ extern "C" {
|
||||
#include "std.h"
|
||||
#include "types.h"
|
||||
#include "errors.h"
|
||||
#include "mystr.h"
|
||||
#include "cptr.h"
|
||||
|
||||
// executes codeblock and prints execution time
|
||||
#ifdef CLOCK_REALTIME // non-standard high-precision clock
|
||||
|
||||
36
base/cptr.c
Normal file
36
base/cptr.c
Normal file
@ -0,0 +1,36 @@
|
||||
#include "base.h"
|
||||
|
||||
// returns length of string (including \0)
|
||||
uint32 cptr_length(char* str){
|
||||
uint32 len=0;
|
||||
while(*(str++)) len++;
|
||||
return ++len;
|
||||
}
|
||||
|
||||
// allocates new char[] and copies src there
|
||||
char* cptr_copy(char* src){
|
||||
uint32 len=cptr_length(src);
|
||||
char* dst=malloc(len*sizeof(char));
|
||||
while(len-->0)
|
||||
dst[len]=src[len];
|
||||
return dst;
|
||||
}
|
||||
|
||||
// compares two char buffers, NullPtr-friendly
|
||||
bool cptr_compare(char* key0, char* key1){
|
||||
if(!key0) return key1 ? false : true;
|
||||
if(!key1) return false;
|
||||
while(*key0&&*key1)
|
||||
if(*key0++ != *key1++)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// multiplies char n times
|
||||
char* char_multiply(char c, uint32 n){
|
||||
char* rez=malloc(n+1);
|
||||
rez[n]=0;
|
||||
while(n-->0)
|
||||
rez[n]=c;
|
||||
return rez;
|
||||
}
|
||||
23
base/cptr.h
Normal file
23
base/cptr.h
Normal file
@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#if __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "types.h"
|
||||
|
||||
// returns length of string (including \0)
|
||||
uint32 cptr_length(char* str);
|
||||
|
||||
// allocates new char[] and copies src there
|
||||
char* cptr_copy(char* src);
|
||||
|
||||
// compares two char buffers, NullPtr-friendly
|
||||
bool cptr_compare(char* key0, char* key1);
|
||||
|
||||
// multiplies char n times
|
||||
char* char_multiply(char c, uint32 n);
|
||||
|
||||
#if __cplusplus
|
||||
}
|
||||
#endif
|
||||
@ -1,6 +1,6 @@
|
||||
#include "std.h"
|
||||
#include "errors.h"
|
||||
#include "mystr.h"
|
||||
#include "cptr.h"
|
||||
|
||||
char* errname(err_t err){
|
||||
switch(err){
|
||||
|
||||
@ -207,7 +207,7 @@
|
||||
<ClInclude Include="Autoarr\StringBuilder.h" />
|
||||
<ClInclude Include="base\base.h" />
|
||||
<ClInclude Include="base\errors.h" />
|
||||
<ClInclude Include="base\mystr.h" />
|
||||
<ClInclude Include="base\cptr.h" />
|
||||
<ClInclude Include="base\std.h" />
|
||||
<ClInclude Include="base\types.h" />
|
||||
<ClInclude Include="DtsodParser\DtsodV24.h" />
|
||||
|
||||
@ -33,7 +33,7 @@
|
||||
<ClInclude Include="base\errors.h">
|
||||
<Filter>Файлы заголовков</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="base\mystr.h">
|
||||
<ClInclude Include="base\cptr.h">
|
||||
<Filter>Файлы заголовков</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="base\std.h">
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#include "tests.h"
|
||||
#include "../base/mystr.h"
|
||||
#include "../String/string.h"
|
||||
|
||||
void test_string(){
|
||||
optime(__func__,1,({
|
||||
|
||||
Loading…
Reference in New Issue
Block a user