Value Converters
convert_to_bool_string
Turns a value into a bool string, suitable for an XML. It is case-insensitive, meaning that the words can also be capitalised.
Accepted values
- "false", "0", "0.0", "no", "non", "nein" -> "false"
- "true", "1", "1.0", "yes", "oui", "ja" -> "true"
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
Any
|
value to transform |
required |
Returns:
Type | Description |
---|---|
str
|
'true' or 'false' if it is an accepted value, |
str
|
else it returns the original value as a string. |
Source code in dsp/dsp-tools/src/dsp_tools/xmllib/value_converters.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
|
replace_newlines_with_tags
Converts the newlines in a string to XML tags. The type of tags is specified through the converter_option enum.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
string to convert |
required |
converter_option
|
NewlineReplacement
|
tag options |
required |
Returns:
Type | Description |
---|---|
str
|
String with replaced values |
Source code in dsp/dsp-tools/src/dsp_tools/xmllib/value_converters.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|
replace_newlines_with_paragraph_tags
Replace Start\nEnd
with <p>Start</p><p>End</p>
Multiple consecutive newlines will be treated as one newline:
Start\nMiddle\n\nEnd
becomes <p>Start</p><p>Middle</p><p>End</p>
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
string to be formatted |
required |
Returns:
Type | Description |
---|---|
str
|
Formatted string with paragraph tags |
Source code in dsp/dsp-tools/src/dsp_tools/xmllib/value_converters.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
replace_newlines_with_br_tags
Replaces Start\nEnd
with Start<br/>End
Multiple consecutive newlines will be converted into multiple break-lines:
Start\n\nEnd
with Start<br/><br/>End
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
string to be formatted |
required |
Returns:
Type | Description |
---|---|
str
|
Formatted string with break-line tags |
Source code in dsp/dsp-tools/src/dsp_tools/xmllib/value_converters.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|