Value Converters
convert_to_bool
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 |
---|---|
bool
|
|
Examples:
result = xmllib.convert_to_bool_string(1)
# result == True
result = xmllib.convert_to_bool_string("nein")
# result == False
result = xmllib.convert_to_bool_string(None)
# raises InputError
Source code in dsp/dsp-tools/src/dsp_tools/xmllib/value_converters.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
|
replace_newlines_with_tags
Converts the newlines in a string to XML tags.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
string to convert |
required |
converter_option
|
NewlineReplacement
|
specifies what tag to use instead of the newline |
required |
Returns:
Type | Description |
---|---|
str
|
String with replaced values |
Examples:
result = xmllib.replace_newlines_with_tags(
"Start\nEnd", xmllib.NewlineReplacement.NONE
)
# result == "Start\nEnd"
result = xmllib.replace_newlines_with_tags(
"Start\nEnd", xmllib.NewlineReplacement.LINEBREAK
)
# result == "Start<br/>End"
result = xmllib.replace_newlines_with_tags(
"Start\n\nEnd", xmllib.NewlineReplacement.PARAGRAPH
)
# result == "<p>Start</p><p>End</p>"
Source code in dsp/dsp-tools/src/dsp_tools/xmllib/value_converters.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
replace_newlines_with_paragraph_tags
Replace Start\nEnd
with <p>Start</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 |
Examples:
result = xmllib.replace_newlines_with_paragraph_tags("Start\nEnd")
# result == "<p>Start</p><p>End</p>"
# multiple consecutive newlines will be treated as one newline
result = xmllib.replace_newlines_with_paragraph_tags("Start\n\nEnd")
# result == "<p>Start</p><p>End</p>"
Source code in dsp/dsp-tools/src/dsp_tools/xmllib/value_converters.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
|
replace_newlines_with_br_tags
Replaces \n
with <br/>
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str
|
string to be formatted |
required |
Returns:
Type | Description |
---|---|
str
|
Formatted string with break-line tags |
Examples:
result = xmllib.replace_newlines_with_br_tags("Start\nEnd")
# result == "Start<br/>End"
# multiple consecutive newlines will be converted into multiple break-lines
result = xmllib.replace_newlines_with_br_tags("Start\n\nEnd")
# result == "Start<br/><br/>End"
Source code in dsp/dsp-tools/src/dsp_tools/xmllib/value_converters.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
|