1 /* 2 * Copyright (C) 2007-2014 Red Hat, Inc. 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2.1 of the License, or (at your option) any later version. 8 * 9 * This library 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 GNU 12 * Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public 15 * License along with this library. If not, see 16 * <http://www.gnu.org/licenses/>. 17 */ 18 19 #pragma once 20 21 #include "internal.h" 22 23 #define VIR_INT64_STR_BUFLEN 21 24 25 int virStrToLong_i(char const *s, 26 char **end_ptr, 27 int base, 28 int *result) 29 G_GNUC_WARN_UNUSED_RESULT; 30 31 int virStrToLong_ui(char const *s, 32 char **end_ptr, 33 int base, 34 unsigned int *result) 35 G_GNUC_WARN_UNUSED_RESULT; 36 int virStrToLong_uip(char const *s, 37 char **end_ptr, 38 int base, 39 unsigned int *result) 40 G_GNUC_WARN_UNUSED_RESULT; 41 int virStrToLong_l(char const *s, 42 char **end_ptr, 43 int base, 44 long *result) 45 G_GNUC_WARN_UNUSED_RESULT; 46 int virStrToLong_ul(char const *s, 47 char **end_ptr, 48 int base, 49 unsigned long *result) 50 G_GNUC_WARN_UNUSED_RESULT; 51 int virStrToLong_ulp(char const *s, 52 char **end_ptr, 53 int base, 54 unsigned long *result) 55 G_GNUC_WARN_UNUSED_RESULT; 56 int virStrToLong_ll(char const *s, 57 char **end_ptr, 58 int base, 59 long long *result) 60 G_GNUC_WARN_UNUSED_RESULT; 61 int virStrToLong_ull(char const *s, 62 char **end_ptr, 63 int base, 64 unsigned long long *result) 65 G_GNUC_WARN_UNUSED_RESULT; 66 int virStrToLong_ullp(char const *s, 67 char **end_ptr, 68 int base, 69 unsigned long long *result) 70 G_GNUC_WARN_UNUSED_RESULT; 71 int virStrToDouble(char const *s, 72 char **end_ptr, 73 double *result) 74 G_GNUC_WARN_UNUSED_RESULT; 75 76 int virDoubleToStr(char **strp, double number) 77 ATTRIBUTE_NONNULL(1); 78 79 void virSkipSpaces(const char **str) ATTRIBUTE_NONNULL(1); 80 void virSkipSpacesAndBackslash(const char **str) ATTRIBUTE_NONNULL(1); 81 void virSkipToDigit(const char **str) ATTRIBUTE_NONNULL(1); 82 void virTrimSpaces(char *str, char **endp) ATTRIBUTE_NONNULL(1); 83 void virSkipSpacesBackwards(const char *str, char **endp) 84 ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); 85 86 bool virStringIsEmpty(const char *str); 87 88 int virStrcpy(char *dest, const char *src, size_t destbytes); 89 #define virStrcpyStatic(dest, src) virStrcpy((dest), (src), sizeof(dest)) 90 91 int virStringSortCompare(const void *a, const void *b); 92 int virStringSortRevCompare(const void *a, const void *b); 93 int virStringToUpper(char **dst, const char *src); 94 95 ssize_t virStringSearch(const char *str, 96 const char *regexp, 97 size_t max_results, 98 char ***matches) 99 ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(4); 100 101 bool virStringMatch(const char *str, 102 const char *regexp); 103 104 char *virStringReplace(const char *haystack, 105 const char *oldneedle, 106 const char *newneedle) 107 ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); 108 109 bool virStringHasSuffix(const char *str, 110 const char *suffix); 111 bool virStringHasCaseSuffix(const char *str, 112 const char *suffix); 113 bool virStringStripSuffix(char *str, 114 const char *suffix) G_GNUC_WARN_UNUSED_RESULT; 115 bool virStringMatchesNameSuffix(const char *file, 116 const char *name, 117 const char *suffix); 118 119 void virStringStripIPv6Brackets(char *str); 120 bool virStringHasChars(const char *str, 121 const char *chars); 122 bool virStringHasControlChars(const char *str); 123 void virStringStripControlChars(char *str); 124 void virStringFilterChars(char *str, const char *valid); 125 126 bool virStringIsPrintable(const char *str); 127 bool virStringBufferIsPrintable(const uint8_t *buf, size_t buflen); 128 129 void virStringTrimOptionalNewline(char *str); 130 131 int virStringParsePort(const char *str, 132 unsigned int *port) 133 ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT; 134 135 int virStringParseYesNo(const char *str, 136 bool *result) 137 G_GNUC_WARN_UNUSED_RESULT; 138