UCSString.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (C) 2007-2011 Siemens AG
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Lesser General Public License as published
  6. * by the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU Lesser General Public License for more details.
  13. * GNU Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /*******************************************************************
  19. *
  20. * @author Daniel.Peintner.EXT@siemens.com
  21. * @version 2011-12-02
  22. * @contact Joerg.Heuer@siemens.com
  23. *
  24. * <p>Code generated by EXIdizer</p>
  25. ********************************************************************/
  26. #include <string.h>
  27. #include "DecoderChannel.h"
  28. #include "BitInputStream.h"
  29. #include "EXITypes.h"
  30. #ifndef UCS_STRING_C
  31. #define UCS_STRING_C
  32. int toUCSString(char* chars, string_ucs_t* s) {
  33. unsigned int i;
  34. s->len = strlen(chars);
  35. if (s->len <= s->size) {
  36. for(i=0; i<s->len; i++) {
  37. s->codepoints[i] = chars[i];
  38. }
  39. return 0;
  40. } else {
  41. return EXI_ERROR_OUT_OF_STRING_BUFFER;
  42. }
  43. }
  44. /* Note A: fails if string contains non ASCII characters */
  45. /* Note B: causes harm if char array is not sufficiently long */
  46. int toASCIIString(string_ucs_t* string, char* outASCII) {
  47. unsigned int i;
  48. for(i=0; i<string->len; i++) {
  49. outASCII[i] = (char)string->codepoints[i];
  50. }
  51. outASCII[string->len] = '\0';
  52. return 0;
  53. }
  54. #endif