Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:13:16

0001 // Protocol Buffers - Google's data interchange format
0002 // Copyright 2023 Google LLC.  All rights reserved.
0003 // https://developers.google.com/protocol-buffers/
0004 //
0005 // Use of this source code is governed by a BSD-style
0006 // license that can be found in the LICENSE file or at
0007 // https://developers.google.com/open-source/licenses/bsd
0008 #ifndef UPB_BASE_STRING_VIEW_H_
0009 #define UPB_BASE_STRING_VIEW_H_
0010 
0011 #include <string.h>
0012 
0013 // Must be last.
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 // LINT.IfChange(struct_definition)
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 // LINT.ThenChange(
0049 //  GoogleInternalName1,
0050 //  //depot/google3/third_party/upb/bits/golang/accessor.go:map_go_string,
0051 //  //depot/google3/third_party/upb/bits/typescript/string_view.ts
0052 // )
0053 
0054 #ifdef __cplusplus
0055 } /* extern "C" */
0056 #endif
0057 
0058 #include "upb/port/undef.inc"
0059 
0060 #endif /* UPB_BASE_STRING_VIEW_H_ */