1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package io.netty5.util;
16
17 import static io.netty5.util.ByteProcessorUtils.CARRIAGE_RETURN;
18 import static io.netty5.util.ByteProcessorUtils.HTAB;
19 import static io.netty5.util.ByteProcessorUtils.LINE_FEED;
20 import static io.netty5.util.ByteProcessorUtils.SPACE;
21
22
23
24
25 public interface ByteProcessor {
26
27
28
29 class IndexOfProcessor implements ByteProcessor {
30 private final byte byteToFind;
31
32 public IndexOfProcessor(byte byteToFind) {
33 this.byteToFind = byteToFind;
34 }
35
36 @Override
37 public boolean process(byte value) {
38 return value != byteToFind;
39 }
40 }
41
42
43
44
45 class IndexNotOfProcessor implements ByteProcessor {
46 private final byte byteToNotFind;
47
48 public IndexNotOfProcessor(byte byteToNotFind) {
49 this.byteToNotFind = byteToNotFind;
50 }
51
52 @Override
53 public boolean process(byte value) {
54 return value == byteToNotFind;
55 }
56 }
57
58
59
60
61 ByteProcessor FIND_NUL = new IndexOfProcessor((byte) 0);
62
63
64
65
66 ByteProcessor FIND_NON_NUL = new IndexNotOfProcessor((byte) 0);
67
68
69
70
71 ByteProcessor FIND_CR = new IndexOfProcessor(CARRIAGE_RETURN);
72
73
74
75
76 ByteProcessor FIND_NON_CR = new IndexNotOfProcessor(CARRIAGE_RETURN);
77
78
79
80
81 ByteProcessor FIND_LF = new IndexOfProcessor(LINE_FEED);
82
83
84
85
86 ByteProcessor FIND_NON_LF = new IndexNotOfProcessor(LINE_FEED);
87
88
89
90
91 ByteProcessor FIND_SEMI_COLON = new IndexOfProcessor((byte) ';');
92
93
94
95
96 ByteProcessor FIND_COMMA = new IndexOfProcessor((byte) ',');
97
98
99
100
101 ByteProcessor FIND_ASCII_SPACE = new IndexOfProcessor(SPACE);
102
103
104
105
106 ByteProcessor FIND_CRLF = value -> value != CARRIAGE_RETURN && value != LINE_FEED;
107
108
109
110
111 ByteProcessor FIND_NON_CRLF = value -> value == CARRIAGE_RETURN || value == LINE_FEED;
112
113
114
115
116 ByteProcessor FIND_LINEAR_WHITESPACE = value -> value != SPACE && value != HTAB;
117
118
119
120
121 ByteProcessor FIND_NON_LINEAR_WHITESPACE = value -> value == SPACE || value == HTAB;
122
123
124
125
126
127 boolean process(byte value);
128 }