fatfs/src/ff.c
static DWORD tchar2uni (	/* Returns character in UTF-16 encoding (>=0x10000 on double encoding unit, 0xFFFFFFFF on decode error) */
	const TCHAR** str		/* Pointer to pointer to TCHAR string in configured encoding */
)
{
	DWORD uc;
	const TCHAR *p = *str;

#if FF_LFN_UNICODE == 1		/* UTF-16 input */
	WCHAR wc;

	uc = *p++;	/* Get a unit */
	if (IsSurrogate(uc)) {	/* Surrogate? */
		wc = *p++;		/* Get low surrogate */
		if (!IsSurrogateH(uc) || !IsSurrogateL(wc)) return 0xFFFFFFFF;	/* Wrong surrogate? */
		uc = uc << 16 | wc;
	}

#elif FF_LFN_UNICODE == 2	/* UTF-8 input */
	BYTE b;
	int nf;

	uc = (BYTE)*p++;	/* Get a unit */
	if (uc & 0x80) {	/* Multiple byte code? */
		if ((uc & 0xE0) == 0xC0) {	/* 2-byte sequence? */
			uc &= 0x1F; nf = 1;
		} else {
			if ((uc & 0xF0) == 0xE0) {	/* 3-byte sequence? */
				uc &= 0x0F; nf = 2;
			} else {
				if ((uc & 0xF8) == 0xF0) {	/* 4-byte sequence? */
					uc &= 0x07; nf = 3;
				} else {					/* Wrong sequence */
					return 0xFFFFFFFF;
				}
			}
		}
		do {	/* Get trailing bytes */
			b = (BYTE)*p++;
			if ((b & 0xC0) != 0x80) return 0xFFFFFFFF;	/* Wrong sequence? */
			uc = uc << 6 | (b & 0x3F);
		} while (--nf != 0);
		if (uc < 0x80 || IsSurrogate(uc) || uc >= 0x110000) return 0xFFFFFFFF;	/* Wrong code? */
		if (uc >= 0x010000) uc = 0xD800DC00 | ((uc - 0x10000) << 6 & 0x3FF0000) | (uc & 0x3FF);	/* Make a surrogate pair if needed */
	}

#elif FF_LFN_UNICODE == 3	/* UTF-32 input */
	uc = (TCHAR)*p++;	/* Get a unit */
	if (uc >= 0x110000) return 0xFFFFFFFF;	/* Wrong code? */
	if (uc >= 0x010000) uc = 0xD800DC00 | ((uc - 0x10000) << 6 & 0x3FF0000) | (uc & 0x3FF);	/* Make a surrogate pair if needed */

#else		/* ANSI/OEM input */
	BYTE b;
	WCHAR wc;

	wc = (BYTE)*p++;			/* Get a byte */
	if (dbc_1st((BYTE)wc)) {	/* Is it a DBC 1st byte? */
		b = (BYTE)*p++;			/* Get 2nd byte */
		if (!dbc_2nd(b)) return 0xFFFFFFFF;	/* Invalid code? */
		wc = (wc << 8) + b;		/* Make a DBC */
	}
	if (wc != 0) {
		wc = ff_oem2uni(wc, CODEPAGE);	/* ANSI/OEM ==> Unicode */
		if (wc == 0) return 0xFFFFFFFF;	/* Invalid code? */
	}
	uc = wc;

#endif
	*str = p;	/* Next read pointer */
	return uc;
}
/* Get a character from TCHAR string in defined API encodeing */
Get a character from TCHAR string in defined API encodeing
Get a character from TCHAR string in defined API encodeing
static DWORD tchar2uni (	
	const TCHAR** str		
)
{
	DWORD uc;
	const TCHAR *p = *str;
#if FF_LFN_UNICODE == 1		
	WCHAR wc;
	uc = *p++;	
	if (IsSurrogate(uc)) {	
		wc = *p++;		
		if (!IsSurrogateH(uc) || !IsSurrogateL(wc)) return 0xFFFFFFFF;	
		uc = uc << 16 | wc;
	}
#elif FF_LFN_UNICODE == 2	
	BYTE b;
	int nf;
	uc = (BYTE)*p++;	
	if (uc & 0x80) {	
		if ((uc & 0xE0) == 0xC0) {	
			uc &= 0x1F; nf = 1;
		} else {
			if ((uc & 0xF0) == 0xE0) {	
				uc &= 0x0F; nf = 2;
			} else {
				if ((uc & 0xF8) == 0xF0) {	
					uc &= 0x07; nf = 3;
				} else {					
					return 0xFFFFFFFF;
				}
			}
		}
		do {	
			b = (BYTE)*p++;
			if ((b & 0xC0) != 0x80) return 0xFFFFFFFF;	
			uc = uc << 6 | (b & 0x3F);
		} while (--nf != 0);
		if (uc < 0x80 || IsSurrogate(uc) || uc >= 0x110000) return 0xFFFFFFFF;	
		if (uc >= 0x010000) uc = 0xD800DC00 | ((uc - 0x10000) << 6 & 0x3FF0000) | (uc & 0x3FF);	
	}
#elif FF_LFN_UNICODE == 3	
	uc = (TCHAR)*p++;	
	if (uc >= 0x110000) return 0xFFFFFFFF;	
	if (uc >= 0x010000) uc = 0xD800DC00 | ((uc - 0x10000) << 6 & 0x3FF0000) | (uc & 0x3FF);	
#else		
	BYTE b;
	WCHAR wc;
	wc = (BYTE)*p++;			
	if (dbc_1st((BYTE)wc)) {	
		b = (BYTE)*p++;			
		if (!dbc_2nd(b)) return 0xFFFFFFFF;	
		wc = (wc << 8) + b;		
	}
	if (wc != 0) {
		wc = ff_oem2uni(wc, CODEPAGE);	
		if (wc == 0) return 0xFFFFFFFF;	
	}
	uc = wc;
#endif
	*str = p;	
	return uc;
}
static DWORD tchar2uni ( const TCHAR * * str ) { DWORD uc ; const TCHAR * p = * str ; #if FF_LFN_UNICODE == 1 WCHAR wc ; uc = * p ++ ; if ( IsSurrogate ( uc ) ) { wc = * p ++ ; if ( ! IsSurrogateH ( uc ) || ! IsSurrogateL ( wc ) ) return 0xFFFFFFFF ; uc = uc << 16 | wc ; } #elif FF_LFN_UNICODE == 2 BYTE b ; int nf ; uc = ( BYTE ) * p ++ ; if ( uc & 0x80 ) { if ( ( uc & 0xE0 ) == 0xC0 ) { uc &= 0x1F ; nf = 1 ; } else { if ( ( uc & 0xF0 ) == 0xE0 ) { uc &= 0x0F ; nf = 2 ; } else { if ( ( uc & 0xF8 ) == 0xF0 ) { uc &= 0x07 ; nf = 3 ; } else { return 0xFFFFFFFF ; } } } do { b = ( BYTE ) * p ++ ; if ( ( b & 0xC0 ) != 0x80 ) return 0xFFFFFFFF ; uc = uc << 6 | ( b & 0x3F ) ; } while ( -- nf != 0 ) ; if ( uc < 0x80 || IsSurrogate ( uc ) || uc >= 0x110000 ) return 0xFFFFFFFF ; if ( uc >= 0x010000 ) uc = 0xD800DC00 | ( ( uc - 0x10000 ) << 6 & 0x3FF0000 ) | ( uc & 0x3FF ) ; } #elif FF_LFN_UNICODE == 3 uc = ( TCHAR ) * p ++ ; if ( uc >= 0x110000 ) return 0xFFFFFFFF ; if ( uc >= 0x010000 ) uc = 0xD800DC00 | ( ( uc - 0x10000 ) << 6 & 0x3FF0000 ) | ( uc & 0x3FF ) ; #else BYTE b ; WCHAR wc ; wc = ( BYTE ) * p ++ ; if ( dbc_1st ( ( BYTE ) wc ) ) { b = ( BYTE ) * p ++ ; if ( ! dbc_2nd ( b ) ) return 0xFFFFFFFF ; wc = ( wc << 8 ) + b ; } if ( wc != 0 ) { wc = ff_oem2uni ( wc , CODEPAGE ) ; if ( wc == 0 ) return 0xFFFFFFFF ; } uc = wc ; #endif * str = p ; return uc ; }
Get a character from TCHAR string in defined API encodeing
Get a character from TCHAR string in defined API encodeing
/* Returns character in UTF-16 encoding (>=0x10000 on double encoding unit, 0xFFFFFFFF on decode error) */ /* Pointer to pointer to TCHAR string in configured encoding */ /* UTF-16 input */ /* Get a unit */ /* Surrogate? */ /* Get low surrogate */ /* Wrong surrogate? */ /* UTF-8 input */ /* Get a unit */ /* Multiple byte code? */ /* 2-byte sequence? */ /* 3-byte sequence? */ /* 4-byte sequence? */ /* Wrong sequence */ /* Get trailing bytes */ /* Wrong sequence? */ /* Wrong code? */ /* Make a surrogate pair if needed */ /* UTF-32 input */ /* Get a unit */ /* Wrong code? */ /* Make a surrogate pair if needed */ /* ANSI/OEM input */ /* Get a byte */ /* Is it a DBC 1st byte? */ /* Get 2nd byte */ /* Invalid code? */ /* Make a DBC */ /* ANSI/OEM ==> Unicode */ /* Invalid code? */ /* Next read pointer */