This commit is contained in:
vrd
2023-01-16 12:01:08 +02:00
parent b49e422cda
commit 25bcd2e22b
6 changed files with 130 additions and 50 deletions
+13 -3
View File
@@ -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;
}