[sword-cvs] sword/src/modules/filters unicodertf.cpp,1.12,1.13

sword@www.crosswire.org sword@www.crosswire.org
Sat, 5 Apr 2003 01:04:48 -0700


Update of /usr/local/cvsroot/sword/src/modules/filters
In directory www:/tmp/cvs-serv8701

Modified Files:
	unicodertf.cpp 
Log Message:
fixed UTF-8 decoding bug
removed vestigial code


Index: unicodertf.cpp
===================================================================
RCS file: /usr/local/cvsroot/sword/src/modules/filters/unicodertf.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** unicodertf.cpp	27 Feb 2003 00:56:31 -0000	1.12
--- unicodertf.cpp	5 Apr 2003 08:04:46 -0000	1.13
***************
*** 28,50 ****
  
  	// -------------------------------
- 	bool lastUni = false;
  	for (text = ""; *from; from++) {
  		ch = 0;
  		if ((*from & 128) != 128) {
- //			if ((*from == ' ') && (lastUni))
- //				*to++ = ' ';
  			text += *from;
- 			lastUni = false;
  			continue;
  		}
  		if ((*from & 128) && ((*from & 64) != 64)) {
- // error, should never get here
- //			*from = 'x';
  			continue;
  		}
  		from2[0] = *from;
  		from2[0] <<= 1;
  		int subsequent;
! 		for (subsequent = 1; (*from & 128) && (subsequent < 7); subsequent++) {
  			from2[0] <<= 1;
  			from2[subsequent] = from[subsequent];
--- 28,47 ----
  
  	// -------------------------------
  	for (text = ""; *from; from++) {
  		ch = 0;
+                 //case: ANSI
  		if ((*from & 128) != 128) {
  			text += *from;
  			continue;
  		}
+                 //case: Invalid UTF-8 (illegal continuing byte in initial position)
  		if ((*from & 128) && ((*from & 64) != 64)) {
  			continue;
  		}
+                 //case: 2+ byte codepoint
  		from2[0] = *from;
  		from2[0] <<= 1;
  		int subsequent;
! 		for (subsequent = 1; (from[0] & 128) && (subsequent < 7); subsequent++) {
  			from2[0] <<= 1;
  			from2[subsequent] = from[subsequent];
***************
*** 62,69 ****
  		text += 'u';
  		sprintf(digit, "%d", ch);
! 		for (char *dig = digit; *dig; dig++)
! 			text += *dig;
  		text += '?';
- 		lastUni = true;
  	}
  	   
--- 59,64 ----
  		text += 'u';
  		sprintf(digit, "%d", ch);
!                 text += digit;
  		text += '?';
  	}