Input_UnicodeBig.java 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* Copyright (C) 2004 Free Software Foundation
  2. This file is part of libgcj.
  3. This software is copyrighted work licensed under the terms of the
  4. Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
  5. details. */
  6. package gnu.gcj.convert;
  7. public class Input_UnicodeBig extends BytesToUnicode
  8. {
  9. /** 0, 8, or 16 bits of a partially constructed character. */
  10. char partial;
  11. /** How many bytes of partial are valid. */
  12. int partial_count;
  13. public String getName() { return "UnicodeBig"; }
  14. public int read (char[] outbuffer, int outpos, int count)
  15. {
  16. int origcount = count;
  17. for (;;)
  18. {
  19. if (partial_count == 2)
  20. {
  21. if (count == 0)
  22. break;
  23. if (partial == 0xFEFF)
  24. ; // drop byte order mark
  25. // else if (partial >= 0xFFFe) ERROR;
  26. else
  27. outbuffer[outpos++] = partial;
  28. count--;
  29. partial_count = 0;
  30. partial = 0;
  31. }
  32. else if (inpos >= inlength)
  33. break;
  34. else
  35. {
  36. int b = inbuffer[inpos++] & 0xFF;
  37. partial = (char) (((int) partial << 8) + b);
  38. partial_count++;
  39. }
  40. }
  41. return origcount - count;
  42. }
  43. }