You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
2.5 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /******************************************************************
  2. * $Id: util.c,v 1.2 2005/05/27 19:28:16 snowdrop Exp $
  3. *
  4. * CSOAP Project: A SOAP client/server library in C
  5. * Copyright (C) 2003 Ferhat Ayaz
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Library General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Library General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Library General Public
  18. * License along with this library; if not, write to the
  19. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  20. * Boston, MA 02111-1307, USA.
  21. *
  22. * Email: ayaz@jprogrammer.net
  23. ******************************************************************/
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include <ctype.h>
  27. int parseNS(const char* fullname, char *ns, char *name)
  28. {
  29. int len, i, found;
  30. if (fullname == NULL || ns == NULL || name == NULL) return 0;
  31. len = strlen(fullname);
  32. found = 0;
  33. for (i = len - 1; i > 0; i--)
  34. {
  35. if (fullname[i] == ':') { found = 1; break; }
  36. }
  37. if (found) strncpy(ns, fullname, i);
  38. else ns[0] = '\0';
  39. strcpy(name,
  40. (fullname[i] == ':')?
  41. (&fullname[i+1]):(&fullname[i]));
  42. return 1;
  43. }
  44. void toUpperCase(const char* src, char *dest)
  45. {
  46. int i, len;
  47. if (src == NULL) return;
  48. len = strlen(src);
  49. for (i=0;i<len;i++) dest[i] = toupper(src[i]);
  50. dest[i] = '\0';
  51. }
  52. void toLowerCase(const char* src, char *dest)
  53. {
  54. int i, len;
  55. if (src == NULL) return;
  56. len = strlen(src);
  57. for (i=0;i<len;i++) dest[i] = tolower(src[i]);
  58. dest[i] = '\0';
  59. }
  60. int test_parseNS_main(int argc, char *argv[])
  61. {
  62. char ns[50];
  63. char name[50];
  64. char *fullname1 = "xsd:test1";
  65. char *fullname2 = ":test2";
  66. char *fullname3 = "test3";
  67. char *fullname4 = "test4:";
  68. ns[0] = '\0'; name[0] = '\0';
  69. if (parseNS(fullname1, ns, name)) {
  70. printf("%-5s | %-10s\n", ns, name);
  71. }
  72. ns[0] = '\0'; name[0] = '\0';
  73. if (parseNS(fullname2, ns, name)) {
  74. printf("%-5s | %-10s\n", ns, name);
  75. }
  76. ns[0] = '\0'; name[0] = '\0';
  77. if (parseNS(fullname3, ns, name)) {
  78. printf("%-5s | %-10s\n", ns, name);
  79. }
  80. ns[0] = '\0'; name[0] = '\0';
  81. if (parseNS(fullname4, ns, name)) {
  82. printf("%-5s | %-10s\n", ns, name);
  83. }
  84. return 0;
  85. }