nu_command/strings/
mod.rs1mod ansi;
2mod base;
3mod char_;
4mod detect;
5mod detect_columns;
6mod detect_type;
7mod encode_decode;
8mod format;
9mod guess_width;
10mod parse;
11mod split;
12mod str_;
13
14pub use ansi::{Ansi, AnsiLink, AnsiStrip};
15pub use base::{
16 DecodeBase32, DecodeBase32Hex, DecodeBase64, DecodeHex, EncodeBase32, EncodeBase32Hex,
17 EncodeBase64, EncodeHex,
18};
19pub use char_::Char;
20pub use detect::Detect;
21pub use detect_columns::*;
22pub use detect_type::*;
23pub use encode_decode::*;
24pub use format::*;
25pub use parse::*;
26pub use split::*;
27pub use str_::*;
28
29use nu_engine::CallExt;
30use nu_protocol::{
31 ShellError,
32 engine::{Call, EngineState, Stack, StateWorkingSet},
33};
34
35pub fn grapheme_flags(
38 engine_state: &EngineState,
39 stack: &mut Stack,
40 call: &Call,
41) -> Result<bool, ShellError> {
42 let g_flag = call.has_flag(engine_state, stack, "grapheme-clusters")?;
43 if g_flag && call.has_flag(engine_state, stack, "utf-8-bytes")? {
47 Err(ShellError::IncompatibleParametersSingle {
48 msg: "Incompatible flags: --grapheme-clusters (-g) and --utf-8-bytes (-b)".to_string(),
49 span: call.head,
50 })?
51 }
52 if g_flag && call.has_flag(engine_state, stack, "code-points")? {
53 Err(ShellError::IncompatibleParametersSingle {
54 msg: "Incompatible flags: --grapheme-clusters (-g) and --code-points (-c)".to_string(),
55 span: call.head,
56 })?
57 }
58 if g_flag && call.has_flag(engine_state, stack, "chars")? {
59 Err(ShellError::IncompatibleParametersSingle {
60 msg: "Incompatible flags: --grapheme-clusters (-g) and --chars (-c)".to_string(),
61 span: call.head,
62 })?
63 }
64 Ok(g_flag)
66}
67
68pub fn grapheme_flags_const(
70 working_set: &StateWorkingSet,
71 call: &Call,
72) -> Result<bool, ShellError> {
73 let g_flag = call.has_flag_const(working_set, "grapheme-clusters")?;
74 if g_flag && call.has_flag_const(working_set, "utf-8-bytes")? {
75 Err(ShellError::IncompatibleParametersSingle {
76 msg: "Incompatible flags: --grapheme-clusters (-g) and --utf-8-bytes (-b)".to_string(),
77 span: call.head,
78 })?
79 }
80 if g_flag && call.has_flag_const(working_set, "code-points")? {
81 Err(ShellError::IncompatibleParametersSingle {
82 msg: "Incompatible flags: --grapheme-clusters (-g) and --utf-8-bytes (-b)".to_string(),
83 span: call.head,
84 })?
85 }
86 Ok(g_flag)
87}