refactor(input_format): extract fn parse_escape.
// limitations under the License.
use chrono_tz::Tz;
+use common_exception::ErrorCode;
+use common_exception::Result;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FormatSettings {
@@ -36,6 +38,30 @@ pub struct FormatSettings {
pub ident_case_sensitive: bool,
}
+impl FormatSettings {
+ pub fn parse_escape(option: &str, default: Option<u8>) -> Result<Option<u8>> {
+ if option.is_empty() {
+ Ok(default)
+ } else if option.len() > 1 {
+ Err(ErrorCode::InvalidArgument(
+ "escape can only contain one char",
+ ))
+ } else {
+ Ok(Some(option.as_bytes()[0]))
+ }
+ }
+
+ pub fn parse_quote(option: &str) -> Result<u8> {
+ if option.len() != 1 {
+ Err(ErrorCode::InvalidArgument(
+ "quote_char can only contain one char",
+ ))
+ } else {
+ Ok(option.as_bytes()[0])
+ }
+ }
+}
+
impl Default for FormatSettings {
fn default() -> Self {
Self {
