Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
admiswalker committed Apr 1, 2022
1 parent e32f785 commit 67ee743
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 28 deletions.
35 changes: 35 additions & 0 deletions sstd/src/string/utf8.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "utf8.hpp"
#include <stdlib.h>
#include <string.h>


size_t sstd_utf8::utf8_to_len(uint8* pStr, size_t size){
size_t len=0; // returning the string length of UTF-8.

for(uint i=0; i<size; ++i){
;
}

return len;
}


sstd::utf8::utf8(): pStr(NULL), _size(0), _alloc_size(0), _len(0) {} // 01
sstd::utf8::utf8(const char* s_in){ // 02
_size = strlen(s_in);
_alloc_size = _size + 1;
pStr = (uint8*)malloc( _alloc_size );
memcpy(pStr, s_in, _size+1);

// len = sstd_utf8::utf8_to_len(pStr);
}
sstd::utf8::~utf8(){ free( pStr ); }

const char* sstd::utf8::begin(){ return (char*)pStr; }
const char* sstd::utf8::c_str(){ return (char*)pStr; }
// const size_t end(){ retrun ; }
const size_t sstd::utf8::size (){ return _size; }
const size_t sstd::utf8::alloc_size(){ return _alloc_size; }
const size_t sstd::utf8::len (){ return _len; }

char& sstd::utf8::operator[](const uint i){ return (char&)pStr[i]; } // OPE.[] does Not guarantee the beginning of UTF-8 character code.
40 changes: 12 additions & 28 deletions sstd/src/string/utf8.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
#pragma once
#include <stdio.h>
#include "../typeDef.h"


Expand All @@ -18,15 +18,7 @@ namespace sstd_utf8{
// rm_CX(); // remove C (Other). C (Other) means "Cc", "Cf", "Cn", "Co" and "Cs".
// rm_CX_owZWJ(); // without ZWJ

size_t utf8_to_len(uint8* pStr, size_t size){
size_t len=0; // returning the string length of UTF-8.
for(uint i=0; i<size; ++i){
;
}
return len;
}
size_t utf8_to_len(uint8* pStr, size_t size);
}

class sstd::utf8{
Expand All @@ -38,25 +30,18 @@ class sstd::utf8{
size_t _len; // length of unicode string // calculated after input.

public:
utf8(): pStr(NULL), _size(0), _alloc_size(0), _len(0) {} // 01
utf8(const char* s_in){ // 02
_size = strlen(s_in);
_alloc_size = _size + 1;
pStr = (uint8*)malloc( _alloc_size );
memcpy(pStr, s_in, _size+1);
// len = sstd_utf8::utf8_to_len(pStr);
}
~utf8(){ free( pStr ); }
utf8();
utf8(const char* s_in);
~utf8();

const char* begin(){ return (char*)pStr; }
const char* c_str(){ return (char*)pStr; }
// const size_t end(){ retrun ; }
const size_t size (){ return _size; }
const size_t alloc_size(){ return _alloc_size; }
const size_t len (){ return _len; }
const char* begin();
const char* c_str();
// const size_t end();
const size_t size ();
const size_t alloc_size();
const size_t len ();

char& operator[](const uint i){ return (char&)pStr[i]; } // OPE.[] does Not guarantee the beginning of UTF-8 character code.
char& operator[](const uint i);

// ==
// !=
Expand All @@ -68,4 +53,3 @@ class sstd::utf8{
// itr.index()
// u8[itr.index()]
};
//*/

0 comments on commit 67ee743

Please sign in to comment.