mirror of
https://github.com/NeoFlock/neonucleus.git
synced 2025-09-24 09:03:32 +02:00
start of unicode lib
This commit is contained in:
parent
7daf034d25
commit
4cfb4f74a6
@ -12,6 +12,7 @@ fn addEngineSources(c: *std.Build.Step.Compile) void {
|
||||
"src/component.c",
|
||||
"src/computer.c",
|
||||
"src/universe.c",
|
||||
"src/unicode.c",
|
||||
// components
|
||||
"src/components/eeprom.c",
|
||||
"src/components/filesystem.c",
|
||||
|
@ -191,6 +191,12 @@ bool ne_fs_isDirectory(nn_component *component, ne_fs *fs, const char *path) {
|
||||
return DirectoryExists(p);
|
||||
}
|
||||
|
||||
bool ne_fs_makeDirectory(nn_component *component, ne_fs *fs, const char *path) {
|
||||
const char *p = ne_fs_diskPath(component, path);
|
||||
|
||||
return MakeDirectory(p) == 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("Setting up universe\n");
|
||||
nn_universe *universe = nn_newUniverse();
|
||||
|
@ -153,6 +153,20 @@ bool nn_removeRef(nn_refc *refc, size_t count);
|
||||
/* Returns true if the object should be freed */
|
||||
bool nn_decRef(nn_refc *refc);
|
||||
|
||||
bool nn_unicode_validate(const char *s);
|
||||
// returned string must be nn_free()'d
|
||||
char *nn_unicode_char(int *codepoints, size_t codepointCount);
|
||||
// returned array must be nn_free()'d
|
||||
int *nn_unicode_codepoints(const char *s);
|
||||
size_t nn_unicode_len(const char *s);
|
||||
int nn_unicode_codepointAt(const char *s, size_t byteOffset);
|
||||
size_t nn_unicode_codepointSize(int codepoint);
|
||||
const char *nn_unicode_codepointToChar(int codepoint, size_t *len);
|
||||
size_t nn_unicode_charWidth(int codepoint);
|
||||
size_t nn_unicode_wlen(const char *s);
|
||||
void nn_unicode_upper(char *s);
|
||||
void nn_unicode_lower(char *s);
|
||||
|
||||
double nn_realTime();
|
||||
double nn_realTimeClock(void *_);
|
||||
/* Will busy-loop until the time passes. This is meant for computed latencies in components. */
|
||||
|
57
src/unicode.c
Normal file
57
src/unicode.c
Normal file
@ -0,0 +1,57 @@
|
||||
#include "neonucleus.h"
|
||||
#include <string.h>
|
||||
|
||||
bool nn_unicode_validate(const char *s) {
|
||||
// TODO: validate UTF-8-ness
|
||||
return true;
|
||||
}
|
||||
|
||||
// A general unicode library, which assumes unicode encoding.
|
||||
// It is used to power the Lua architecture's Unicode API re-implementation.
|
||||
// It can also just be used to deal with unicode.
|
||||
|
||||
char *nn_unicode_char(int *codepoints, size_t codepointCount) {
|
||||
size_t len = 0;
|
||||
for(size_t i = 0; i < codepointCount; i++) {
|
||||
int codepoint = codepoints[i];
|
||||
len += nn_unicode_codepointSize(codepoint);
|
||||
}
|
||||
|
||||
char *buf = nn_malloc(len+1);
|
||||
if(buf == NULL) return buf;
|
||||
buf[len] = '\0';
|
||||
|
||||
size_t j = 0;
|
||||
for(size_t i = 0; i < codepointCount; i++) {
|
||||
int codepoint = codepoints[i];
|
||||
size_t codepointLen = 0;
|
||||
const char *c = nn_unicode_codepointToChar(codepoint, &codepointLen);
|
||||
memcpy(buf + j, c, codepointLen);
|
||||
j += codepointLen;
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
int *nn_unicode_codepoints(const char *s);
|
||||
|
||||
size_t nn_unicode_len(const char *s) {
|
||||
size_t count = 0;
|
||||
while (*s) {
|
||||
count += (*s++ & 0xC0) != 0x80;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
int nn_unicode_codepointAt(const char *s, size_t byteOffset);
|
||||
|
||||
size_t nn_unicode_codepointSize(int codepoint);
|
||||
|
||||
const char *nn_unicode_codepointToChar(int codepoint, size_t *len);
|
||||
|
||||
size_t nn_unicode_charWidth(int codepoint);
|
||||
|
||||
size_t nn_unicode_wlen(const char *s);
|
||||
|
||||
void nn_unicode_upper(char *s);
|
||||
void nn_unicode_lower(char *s);
|
Loading…
x
Reference in New Issue
Block a user