/*** Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved. File: GBK.hpp Date: 2021-11-1 Author: Reece ***/ #pragma once namespace Aurora::Locale::Encoding::GBK { static auline int GetLenGBKCodePoint(const AuUInt8 *in, AuUInt32 len) { if (len == 0) { return 0; } if (in[0] >= 0x80) { if (len < 2) { return 0; } return 2; } return 1; } static inline int CountGbk(const void *base, AuUInt32 length, bool bytes = false) { AuUInt32 i {}, cps {}; for (; i < length; ) { auto next = GetLenGBKCodePoint((const AuUInt8*)base + i, length - i); if (next == 0) { return bytes ? i : cps; } i += next; cps++; } return bytes ? i : cps; } }