1 /* 2 * Copyright (C) 2018 Julien Viet 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 */ 17 module hunt.database.driver.postgresql.impl.util.UTF8StringEndDetector; 18 19 import hunt.net.buffer.ByteProcessor; 20 21 // /** 22 // * A processor that detects the end of a well formed UTF8 string, starting end ending with a {@code "}. 23 // * <p/> 24 // * It process all bytes until it finds the ending {@code "}. 25 // */ 26 // class UTF8StringEndDetector implements ByteProcessor { 27 28 // private boolean inString; 29 // private boolean escaped; 30 31 // override 32 // boolean process(byte value) { 33 // boolean wasEscaped = escaped; 34 // escaped = false; 35 // // In UTF-8 low ASCII have their 8th bit == 0 36 // if ((value & 0b10000000) == 0) { 37 // switch (value) { 38 // case '"': 39 // if (!wasEscaped) { 40 // if (inString) { 41 // return false; 42 // } else { 43 // inString = true; 44 // } 45 // } 46 // break; 47 // case '\\': 48 // if (inString) { 49 // escaped = true; 50 // } 51 // break; 52 // } 53 // } 54 // return true; 55 // } 56 // }