326 sz == 0 ifTrue:[^ '']. |
315 sz == 0 ifTrue:[^ '']. |
327 |
316 |
328 out := WriteStream on:(String new:(sz * 2)). |
317 out := WriteStream on:(String new:(sz * 2)). |
329 |
318 |
330 1 to:sz do:[:srcIndex | |
319 1 to:sz do:[:srcIndex | |
331 c := aJISString at:srcIndex. |
320 c := aJISString at:srcIndex. |
332 b1 := c asciiValue. |
321 b1 := c codePoint. |
333 b1 < 33 ifTrue:[ |
322 b1 < 33 ifTrue:[ |
334 "/ a control character |
323 "/ a control character |
335 inSingleByteMode ifFalse:[ |
324 inSingleByteMode ifFalse:[ |
336 out nextPutAll:roman. |
325 out nextPutAll:roman. |
337 inSingleByteMode := true |
326 inSingleByteMode := true |
338 ]. |
327 ]. |
339 out nextPut:c. |
328 out nextPut:c. |
340 ] ifFalse:[ |
329 ] ifFalse:[ |
341 "/ check for a roman character |
330 "/ check for a roman character |
342 "/ the two numbers below are romanTable min and romanTable max |
331 "/ the two numbers below are romanTable min and romanTable max |
343 (b1 between:16r2121 and:16r2573) ifTrue:[ |
332 (b1 between:16r2121 and:16r2573) ifTrue:[ |
344 val := romans indexOf:b1. |
333 val := romans indexOf:b1. |
345 val2 := val - 1 + 32. |
334 val2 := val - 1 + 32. |
346 (val ~~ 0 and:[val2 <= 16r7F]) ifTrue:[ |
335 (val ~~ 0 and:[val2 <= 16r7F]) ifTrue:[ |
347 inSingleByteMode ifFalse:[ |
336 inSingleByteMode ifFalse:[ |
348 out nextPutAll:roman. |
337 out nextPutAll:roman. |
349 inSingleByteMode := true |
338 inSingleByteMode := true |
350 ]. |
339 ]. |
351 out nextPut:(Character value:val2) |
340 out nextPut:(Character value:val2) |
352 ] ifFalse:[ |
341 ] ifFalse:[ |
353 inSingleByteMode ifTrue:[ |
342 inSingleByteMode ifTrue:[ |
354 out nextPutAll:kanji. |
343 out nextPutAll:kanji. |
355 inSingleByteMode := false |
344 inSingleByteMode := false |
356 ]. |
345 ]. |
357 out nextPut:(Character value:(b1 bitShift:-8)). |
346 out nextPut:(Character value:(b1 bitShift:-8)). |
358 out nextPut:(Character value:(b1 bitAnd:16rFF)). |
347 out nextPut:(Character value:(b1 bitAnd:16rFF)). |
359 ]. |
348 ]. |
360 ] ifFalse:[ |
349 ] ifFalse:[ |
361 b1 <= 255 ifTrue:[ |
350 b1 <= 255 ifTrue:[ |
362 "/ mhmh - unrepresentable roman (national chars) |
351 "/ mhmh - unrepresentable roman (national chars) |
363 "/ b1 >= 160 ifTrue:[ |
352 "/ b1 >= 160 ifTrue:[ |
364 "/ ('no rep for ' , b1 printString) printNL. |
353 "/ ('no rep for ' , b1 printString) printNL. |
365 "/ ]. |
354 "/ ]. |
366 "/ there are non-japanese characters in there... |
355 "/ there are non-japanese characters in there... |
367 "/ assume that is OK (leave as is) ... |
356 "/ assume that is OK (leave as is) ... |
368 "/ EncodingFailedError |
357 "/ EncodingFailedError |
369 "/ raiseWith:aJISString |
358 "/ raiseWith:aJISString |
370 "/ errorString:'JIS7 encoding failed (contains 8-bit characters ?)'. |
359 "/ errorString:'JIS7 encoding failed (contains 8-bit characters ?)'. |
371 |
360 |
372 inSingleByteMode ifFalse:[ |
361 inSingleByteMode ifFalse:[ |
373 out nextPutAll:roman. |
362 out nextPutAll:roman. |
374 inSingleByteMode := true |
363 inSingleByteMode := true |
375 ]. |
364 ]. |
376 out nextPut:c |
365 out nextPut:c |
377 ] ifFalse:[ |
366 ] ifFalse:[ |
378 inSingleByteMode ifTrue:[ |
367 inSingleByteMode ifTrue:[ |
379 out nextPutAll:kanji. |
368 out nextPutAll:kanji. |
380 inSingleByteMode := false |
369 inSingleByteMode := false |
381 ]. |
370 ]. |
382 out nextPut:(Character value:(b1 bitShift:-8)). |
371 out nextPut:(Character value:(b1 bitShift:-8)). |
383 out nextPut:(Character value:(b1 bitAnd:16rFF)). |
372 out nextPut:(Character value:(b1 bitAnd:16rFF)). |
384 ] |
373 ] |
385 ] |
374 ] |
386 ]. |
375 ]. |
387 ]. |
376 ]. |
388 inSingleByteMode ifFalse:[ |
377 inSingleByteMode ifFalse:[ |
389 out nextPutAll:roman. |
378 out nextPutAll:roman. |
390 ]. |
379 ]. |
391 ^ out contents |
380 ^ out contents |
392 |
381 |
393 "simple: |
382 "simple: |
394 |
383 |