summaryrefslogblamecommitdiff
path: root/zap/source/any/mem/utf8declen.c
blob: 99c224b70c9d5de632d68847d45b54b904204048 (plain) (tree)
1
2
3
4
5
6
7
8
9







                                                                                                                     
                                                  
                          
                           
                                 
                                        


















                                    
/*
	Copyright 2022-2023 Gabriel Jensen.
	This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
	If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/

#include <zap/mem.h>

zap_sz zap_utf8declen(zap_i8 const * const _buf) {
	zap_sz len = 0x0u;
	zap_i8 const * pos;
	for (pos = _buf;;++len) {
		zap_i8 const oct = *pos;
		if (oct == 0x0u) {
			break;
		}
		if (oct >= 0xF0u) {
			pos += 0x4u;
			continue;
		}
		if (oct >= 0xE0u) {
			pos += 0x3u;
			continue;
		}
		if (oct >= 0xC0u) {
			pos += 0x2u;
			continue;
		}
		++pos;
	}
	return len;
}