solarium.vlad/PROJECT/app/service_name.c

42 lines
1.0 KiB
C

#include "service_name.h"
char service_name[] = "Услуга загара в солярии";
char* get_service_name()
{
return service_name;
}
// Returns the number of characters in an UTF-8 encoded string.
// (Does not check for encoding validity)
int u8strlen(const char *s)
{
int len=0;
while (*s) {
if ((*s & 0xC0) != 0x80) len++ ;
s++;
}
return len;
}
// Avoids truncating multibyte UTF-8 encoding at the end.
char *u8strncpy(char *dest, const char *src, size_t n)
{
int k = n-1;
int i;
if (n) {
dest[k] = 0;
strncpy(dest,src,n);
if (dest[k] & 0x80) { // Last byte has been overwritten
for (i=k; (i>0) && ((k-i) < 3) && ((dest[i] & 0xC0) == 0x80); i--) ;
switch(k-i) {
case 0: dest[i] = '\0'; break;
case 1: if ( (dest[i] & 0xE0) != 0xC0) dest[i] = '\0'; break;
case 2: if ( (dest[i] & 0xF0) != 0xE0) dest[i] = '\0'; break;
case 3: if ( (dest[i] & 0xF8) != 0xF0) dest[i] = '\0'; break;
}
}
}
return dest;
}