bwstring.h (71ec05a21257e159f40d54e26ad0011bb19b5134) | bwstring.h (d053fb22f6d3b6bb0f4e47e4507fefc20cbe0e32) |
---|---|
1/* $FreeBSD$ */ 2 3/*- 4 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 5 * 6 * Copyright (C) 2009 Gabor Kovesdan <gabor@FreeBSD.org> 7 * Copyright (C) 2012 Oleg Moskalenko <mom040267@gmail.com> 8 * All rights reserved. --- 32 unchanged lines hidden (view full) --- 41#include "sort.h" 42#include "mem.h" 43 44extern bool byte_sort; 45 46/* wchar_t is of 4 bytes: */ 47#define SIZEOF_WCHAR_STRING(LEN) ((LEN)*sizeof(wchar_t)) 48 | 1/* $FreeBSD$ */ 2 3/*- 4 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 5 * 6 * Copyright (C) 2009 Gabor Kovesdan <gabor@FreeBSD.org> 7 * Copyright (C) 2012 Oleg Moskalenko <mom040267@gmail.com> 8 * All rights reserved. --- 32 unchanged lines hidden (view full) --- 41#include "sort.h" 42#include "mem.h" 43 44extern bool byte_sort; 45 46/* wchar_t is of 4 bytes: */ 47#define SIZEOF_WCHAR_STRING(LEN) ((LEN)*sizeof(wchar_t)) 48 |
49struct wstr { 50 size_t len; 51 wchar_t str[]; 52}; 53 54struct cstr { 55 size_t len; 56 char str[]; 57}; 58 |
|
49/* 50 * Binary "wide" string 51 */ 52struct bwstring 53{ | 59/* 60 * Binary "wide" string 61 */ 62struct bwstring 63{ |
54 size_t len; 55 union 56 { 57 wchar_t wstr[0]; 58 unsigned char cstr[0]; 59 } data; | 64 union { 65 struct wstr wdata; 66 struct cstr cdata; 67 }; |
60}; 61 62struct reader_buffer 63{ 64 wchar_t *fgetwln_z_buffer; 65 size_t fgetwln_z_buffer_size; 66}; 67 68typedef void *bwstring_iterator; 69 | 68}; 69 70struct reader_buffer 71{ 72 wchar_t *fgetwln_z_buffer; 73 size_t fgetwln_z_buffer_size; 74}; 75 76typedef void *bwstring_iterator; 77 |
70#define BWSLEN(s) ((s)->len) 71 | 78#define BWSLEN(s) ((mb_cur_max == 1) ? (s)->cdata.len : (s)->wdata.len) |
72struct bwstring *bwsalloc(size_t sz); 73 74size_t bwsrawlen(const struct bwstring *bws); 75const void* bwsrawdata(const struct bwstring *bws); 76void bws_setlen(struct bwstring *bws, size_t newlen); 77size_t bws_memsize(const struct bwstring *bws); 78double bwstod(struct bwstring *s0, bool *empty); 79int bws_month_score(const struct bwstring *s0); --- 18 unchanged lines hidden (view full) --- 98int bwscoll(const struct bwstring *bws1, const struct bwstring *bws2, size_t offset); 99size_t bwsfwrite(struct bwstring *bws, FILE *f, bool zero_ended); 100struct bwstring *bwsfgetln(FILE *file, size_t *len, bool zero_ended, struct reader_buffer *rb); 101 102static inline bwstring_iterator 103bws_begin(struct bwstring *bws) 104{ 105 | 79struct bwstring *bwsalloc(size_t sz); 80 81size_t bwsrawlen(const struct bwstring *bws); 82const void* bwsrawdata(const struct bwstring *bws); 83void bws_setlen(struct bwstring *bws, size_t newlen); 84size_t bws_memsize(const struct bwstring *bws); 85double bwstod(struct bwstring *s0, bool *empty); 86int bws_month_score(const struct bwstring *s0); --- 18 unchanged lines hidden (view full) --- 105int bwscoll(const struct bwstring *bws1, const struct bwstring *bws2, size_t offset); 106size_t bwsfwrite(struct bwstring *bws, FILE *f, bool zero_ended); 107struct bwstring *bwsfgetln(FILE *file, size_t *len, bool zero_ended, struct reader_buffer *rb); 108 109static inline bwstring_iterator 110bws_begin(struct bwstring *bws) 111{ 112 |
106 return (bwstring_iterator) (&(bws->data)); | 113 return ((bwstring_iterator)bws->wdata.str); |
107} 108 109static inline bwstring_iterator 110bws_end(struct bwstring *bws) 111{ 112 113 return ((mb_cur_max == 1) ? | 114} 115 116static inline bwstring_iterator 117bws_end(struct bwstring *bws) 118{ 119 120 return ((mb_cur_max == 1) ? |
114 (bwstring_iterator) (bws->data.cstr + bws->len) : 115 (bwstring_iterator) (bws->data.wstr + bws->len)); | 121 (bwstring_iterator) (bws->cdata.str + bws->cdata.len) : 122 (bwstring_iterator) (bws->wdata.str + bws->wdata.len)); |
116} 117 118static inline bwstring_iterator 119bws_iterator_inc(bwstring_iterator iter, size_t pos) 120{ 121 122 if (mb_cur_max == 1) 123 return ((unsigned char *) iter) + pos; --- 9 unchanged lines hidden (view full) --- 133 return *((unsigned char *) iter); 134 else 135 return *((wchar_t*) iter); 136} 137 138int 139bws_iterator_cmp(bwstring_iterator iter1, bwstring_iterator iter2, size_t len); 140 | 123} 124 125static inline bwstring_iterator 126bws_iterator_inc(bwstring_iterator iter, size_t pos) 127{ 128 129 if (mb_cur_max == 1) 130 return ((unsigned char *) iter) + pos; --- 9 unchanged lines hidden (view full) --- 140 return *((unsigned char *) iter); 141 else 142 return *((wchar_t*) iter); 143} 144 145int 146bws_iterator_cmp(bwstring_iterator iter1, bwstring_iterator iter2, size_t len); 147 |
141#define BWS_GET(bws, pos) ((mb_cur_max == 1) ? ((bws)->data.cstr[(pos)]) : (bws)->data.wstr[(pos)]) | 148#define BWS_GET(bws, pos) ((mb_cur_max == 1) ? (bws->cdata.str[(pos)]) : bws->wdata.str[(pos)]) |
142 143void initialise_months(void); 144 145#endif /* __BWSTRING_H__ */ | 149 150void initialise_months(void); 151 152#endif /* __BWSTRING_H__ */ |