utf8 len
This commit is contained in:
+13
-3
@@ -1,5 +1,6 @@
|
||||
#include <iostream>
|
||||
#include <assert.h>
|
||||
#include<ctype.h>
|
||||
#include <ncursesw/ncurses.h>
|
||||
|
||||
#include"person.h"
|
||||
@@ -90,10 +91,10 @@ void Person::save(std::ofstream &file)const
|
||||
|
||||
void Person::load(std::ifstream &file)
|
||||
{
|
||||
char nameLen;
|
||||
U8 nameLen;
|
||||
file.read((char*)&nameLen, sizeof(nameLen)); //Check len
|
||||
|
||||
C8 nameBuf[128];
|
||||
char nameBuf[128];
|
||||
file.read(nameBuf, nameLen * sizeof(*nameBuf));
|
||||
nameBuf[nameLen] = '\0';
|
||||
name_ = nameBuf;
|
||||
@@ -139,9 +140,18 @@ bool Person::isMale() const
|
||||
return isMale_;
|
||||
}
|
||||
|
||||
static U16 strUtf8Symbols(const std::string& str)
|
||||
{
|
||||
U16 num = 0;
|
||||
for(char c: str)
|
||||
num += ((c & 0xC0) != 0x80);
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
U16 Person::boxWidth() const
|
||||
{
|
||||
return name_.size() + 4; /* TODO: get actual lenght */
|
||||
return strUtf8Symbols(name_) + 4;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user