File indexing completed on 2025-01-18 10:13:16
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef UPB_BASE_STRING_VIEW_H_
0009 #define UPB_BASE_STRING_VIEW_H_
0010
0011 #include <string.h>
0012
0013
0014 #include "upb/port/def.inc"
0015
0016 #define UPB_STRINGVIEW_INIT(ptr, len) \
0017 { ptr, len }
0018
0019 #define UPB_STRINGVIEW_FORMAT "%.*s"
0020 #define UPB_STRINGVIEW_ARGS(view) (int)(view).size, (view).data
0021
0022
0023 typedef struct {
0024 const char* data;
0025 size_t size;
0026 } upb_StringView;
0027
0028 #ifdef __cplusplus
0029 extern "C" {
0030 #endif
0031
0032 UPB_API_INLINE upb_StringView upb_StringView_FromDataAndSize(const char* data,
0033 size_t size) {
0034 upb_StringView ret;
0035 ret.data = data;
0036 ret.size = size;
0037 return ret;
0038 }
0039
0040 UPB_INLINE upb_StringView upb_StringView_FromString(const char* data) {
0041 return upb_StringView_FromDataAndSize(data, strlen(data));
0042 }
0043
0044 UPB_INLINE bool upb_StringView_IsEqual(upb_StringView a, upb_StringView b) {
0045 return (a.size == b.size) && (!a.size || !memcmp(a.data, b.data, a.size));
0046 }
0047
0048
0049
0050
0051
0052
0053
0054 #ifdef __cplusplus
0055 }
0056 #endif
0057
0058 #include "upb/port/undef.inc"
0059
0060 #endif