iffId.cxx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /**
  2. * PANDA 3D SOFTWARE
  3. * Copyright (c) Carnegie Mellon University. All rights reserved.
  4. *
  5. * All use of this software is subject to the terms of the revised BSD
  6. * license. You should have received a copy of this license along
  7. * with this source code in a file named "LICENSE."
  8. *
  9. * @file iffId.cxx
  10. * @author drose
  11. * @date 2001-04-23
  12. */
  13. #include "iffId.h"
  14. #include <ctype.h>
  15. /**
  16. *
  17. */
  18. void IffId::
  19. output(std::ostream &out) const {
  20. // If all of the characters are printable, just output them.
  21. if (isprint(_id._c[0]) && isprint(_id._c[1]) &&
  22. isprint(_id._c[2]) && isprint(_id._c[3])) {
  23. out << _id._c[0] << _id._c[1] << _id._c[2] << _id._c[3];
  24. } else if (isprint(_id._c[0]) && isprint(_id._c[1]) &&
  25. isprint(_id._c[2]) && _id._c[3] == '\0') {
  26. // If the last character is 0, output a 3-letter ID.
  27. out << _id._c[0] << _id._c[1] << _id._c[2];
  28. } else {
  29. // Otherwise, write out the hex.
  30. out << "0x" << std::hex << std::setfill('0');
  31. for (int i = 0; i < 4; i++) {
  32. out << std::setw(2) << (int)(unsigned char)_id._c[i];
  33. }
  34. out << std::dec << std::setfill(' ');
  35. }
  36. }