fspr_strtok.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifdef HAVE_STDDEF_H
  17. #include <stddef.h> /* for NULL */
  18. #endif
  19. #include "fspr.h"
  20. #include "fspr_strings.h"
  21. #define APR_WANT_STRFUNC /* for strchr() */
  22. #include "fspr_want.h"
  23. APR_DECLARE(char *) fspr_strtok(char *str, const char *sep, char **last)
  24. {
  25. char *token;
  26. if (!str) /* subsequent call */
  27. str = *last; /* start where we left off */
  28. /* skip characters in sep (will terminate at '\0') */
  29. while (*str && strchr(sep, *str))
  30. ++str;
  31. if (!*str) /* no more tokens */
  32. return NULL;
  33. token = str;
  34. /* skip valid token characters to terminate token and
  35. * prepare for the next call (will terminate at '\0)
  36. */
  37. *last = token + 1;
  38. while (**last && !strchr(sep, **last))
  39. ++*last;
  40. if (**last) {
  41. **last = '\0';
  42. ++*last;
  43. }
  44. return token;
  45. }