StringTable.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright (C) 2007-2010 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. *
  14. * You should have received a copy of the GNU Lesser General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /*******************************************************************
  18. *
  19. * @author Daniel.Peintner.EXT@siemens.com
  20. * @version 0.2.2
  21. * @contact Joerg.Heuer@siemens.com
  22. *
  23. ********************************************************************/
  24. #ifndef STRING_TABLE_C
  25. #define STRING_TABLE_C
  26. #include <stdio.h>
  27. #include <stdint.h>
  28. #include <string.h>
  29. #include <stdlib.h>
  30. #include "StringTable.h"
  31. #include "EXITypes.h"
  32. #include "BitInputStream.h"
  33. #include "BitDecoderChannel.h"
  34. #include "StringTableEntries.h"
  35. #include "assert.h"
  36. int exiGetUri(size_t uriID, const char** uri) {
  37. if ( uriID < stringTable.len ) {
  38. *uri = stringTable.uris[uriID];
  39. } else {
  40. return EXI_ERROR_OUT_OF_BOUNDS;
  41. }
  42. return 0;
  43. }
  44. int exiGetUriLength(size_t* uriLength) {
  45. *uriLength = stringTable.len;
  46. return 0;
  47. }
  48. int exiGetUriID(const char* uri, size_t* uriID) {
  49. unsigned int i;
  50. for(i=0; i<stringTable.len; i++) {
  51. if ( strcmp ( uri, stringTable.uris[i] ) == 0 ) {
  52. *uriID = i;
  53. return 0;
  54. }
  55. }
  56. return -1;
  57. }
  58. int exiGetLocalName(size_t uriID, size_t localNameID, const char** localName) {
  59. if ( uriID < stringTable.len ) {
  60. if ( localNameID < stringTable.localNames[uriID].len ) {
  61. *localName = stringTable.localNames[uriID].entries[localNameID];
  62. } else {
  63. return EXI_ERROR_OUT_OF_BOUNDS;
  64. }
  65. } else {
  66. return EXI_ERROR_OUT_OF_BOUNDS;
  67. }
  68. return 0;
  69. }
  70. int exiGetLocalNameLength(size_t uriID, size_t* localNameLength) {
  71. if ( uriID < stringTable.len ) {
  72. *localNameLength = stringTable.localNames[uriID].len;
  73. } else {
  74. return EXI_ERROR_OUT_OF_BOUNDS;
  75. }
  76. return 0;
  77. }
  78. int exiGetLocalNameID(size_t uriID, const char* localName, size_t* localNameID) {
  79. unsigned int i;
  80. if ( uriID < stringTable.len ) {
  81. /* TODO binary search */
  82. for(i=0; i<stringTable.localNames[uriID].len; i++) {
  83. if ( strcmp ( localName, stringTable.localNames[uriID].entries[i] ) == 0 ) {
  84. *localNameID = i;
  85. return 0;
  86. }
  87. }
  88. } else {
  89. return EXI_ERROR_OUT_OF_BOUNDS;
  90. }
  91. return -1;
  92. }
  93. #endif