summaryrefslogblamecommitdiff
path: root/zp/source/any/str/utf8declen.c
blob: caea2995f3e7e2514b8dafdb812f4ada5fe5fd8c (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 <zp/str.h>

zp_siz zp_utf8declen(zp_c8 const* zp_prv_rsr str) {
	zp_siz len = 0x0u;

	for (;;++len) {
		zp_c8 const oct = *str;
		
		zp_unlik (oct == 0x0u) {break;}

		if (oct >= 0xF0u) {
			str += 0x4u;
			continue;
		}

		if (oct >= 0xE0u) {
			str += 0x3u;
			continue;
		}

		if (oct >= 0xC0u) {
			str += 0x2u;
			continue;
		}
		
		++str;
	}

	return len;
}