Exemple #1
0
int String__strncpy(void *str1, void *str2, int n)
{
	int l1 = strlen(*(void **)str1), l2 = strlen(*(void **)str2);
	char *string1Chars = getStringChars(str1);
	char *string2Chars = getStringChars(str2);
	int returnVal = 0;
	if (isStringType((void **)str1)) {
		String string1 = *(String *)str1;
		if (!(string1.LengthLimit >= MIN(n, l2))) {
			changeStringLength(string1, MIN(n, l2));
			/*  Return the number of extra characters */
			returnVal = MAX(n, l2);
		}
		int newLength = MIN(n, l2);
		string1.Length = newLength;
		string1Chars[newLength] = '\0';
	} else {
		if (l1 <= l1 + MIN(l2, n)) {
		} else {
			fprintf(stderr, "ERROR: stringnfuncs.c:String__strncpy: destination string too short\n");
			returnVal = l1 - MIN(l2, n); //Failure, result < 0
			return returnVal;
		}
	}
	memcpy(string1Chars, string2Chars, (MIN(n, l2)) * sizeof(char));
	return returnVal;
}
Exemple #2
0
char *String2Utf8(Object *string) {
    int len = getStringLen(string);
    unsigned short *unicode = getStringChars(string);
    char *utf8 = (char*)sysMalloc(utf8CharLen(unicode, len) + 1);

    return unicode2Utf8(unicode, len, utf8);
}
Exemple #3
0
char *StringRegion2Utf8(Object *string, int start, int len, char *utf8) {
    return unicode2Utf8(getStringChars(string) + start, len, utf8);
}
Exemple #4
0
int getStringUtf8Len(Object *string) {
    return utf8CharLen(getStringChars(string), getStringLen(string));
}