github.com/vanus-labs/vanus/lib@v0.0.0-20231221070800-1334a7b9605e/json/parse/escape.go (about)

     1  // Copyright 2023 Linkall Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package parse
    16  
    17  import (
    18  	// standard libraries.
    19  	"io"
    20  
    21  	// this project.
    22  	"github.com/vanus-labs/vanus/lib/bytes"
    23  )
    24  
    25  const basicPlan = "" + //nolint:unused // reserved for future use.
    26  	`................................` + // 0x00
    27  	`...............s................` + // 0x20, slash(0x2f)
    28  	`............................s...` + // 0x40, backslash(0x5c)
    29  	"..\b...\f.......\n...\r.\tu.........." + // 0x60
    30  	`................................` + // 0x80
    31  	`................................` + // 0xa0
    32  	`................................` + // 0xc0
    33  	`................................` //  0xe0
    34  
    35  const doubleQuotePlan = "" +
    36  	`................................` + // 0x00
    37  	`..s............s................` + // 0x20, double quote(0x22), slash(0x2f)
    38  	`............................s...` + // 0x40, backslash(0x5c)
    39  	"..\b...\f.......\n...\r.\tu.........." + // 0x60
    40  	`................................` + // 0x80
    41  	`................................` + // 0xa0
    42  	`................................` + // 0xc0
    43  	`................................` //  0xe0
    44  
    45  const singleQuotePlan = "" +
    46  	`................................` + // 0x00
    47  	`.......s.......s................` + // 0x20, single quote(0x27), slash(0x2f)
    48  	`............................s...` + // 0x40, backslash(0x5c)
    49  	`................................` + // 0x40
    50  	"..\b...\f.......\n...\r.\tu.........." + // 0x60
    51  	`................................` + // 0x80
    52  	`................................` + // 0xa0
    53  	`................................` + // 0xc0
    54  	`................................` //  0xe0
    55  
    56  func ConsumeEscapedWithDoubleQuote(r io.ByteReader, w io.ByteWriter) error {
    57  	return bytes.ConsumeEscaped(r, w, doubleQuotePlan)
    58  }
    59  
    60  func ConsumeEscapedWithSingleQuote(r io.ByteReader, w io.ByteWriter) error {
    61  	return bytes.ConsumeEscaped(r, w, singleQuotePlan)
    62  }