File indexing completed on 2026-07-14 08:49:58
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 UPB_INLINE int upb_StringView_Compare(upb_StringView a, upb_StringView b) {
0051 int result = memcmp(a.data, b.data, UPB_MIN(a.size, b.size));
0052 if (result != 0) return result;
0053 if (a.size < b.size) {
0054 return -1;
0055 } else if (a.size > b.size) {
0056 return 1;
0057 } else {
0058 return 0;
0059 }
0060 }
0061
0062
0063
0064
0065
0066
0067
0068 #ifdef __cplusplus
0069 }
0070 #endif
0071
0072 #include "upb/port/undef.inc"
0073
0074 #endif