Library "Text"
library to format text in different fonts or cases plus a sort function.
🔸 Credits and Usage
This library is inspired by the work of three authors (in chronological order of publication date):
🔹 Fonts
Besides extra added font options, the toFont(fromText, font) method uses a different technique. On the first runtime bar (whether it is barstate.isfirst, barstate.islast, or between) regular letters and numbers and mapped with the chosen font. After this, each character is replaced using the build-in key - value pair map function.
Also an enum Efont is included.
Note: Some fonts are not complete, for example there isn't a replacement for every character in Superscript/Subscript.
Example of usage (besides the included table example):
Pine Script®
🔹 Cases
The script includes a toCase(fromText, case) method to transform text into snake_case, UPPER SNAKE_CASE, kebab-case, camelCase or PascalCase, as well as an enum Ecase.
Example of usage (besides the included table example):
Pine Script®
🔹 Sort
The sort(strings, order, sortByUnicodeDecimalNumbers) method returns a sorted array of strings.
_____
• sortByUnicodeDecimalNumbers: every Unicode character is linked to a Unicode Decimal number (wikipedia.org/wiki/List_of_Unicode_characters), for example:
1 49
2 50
3 51
...
A 65
B 66
...
S 83
...
_ 95
` 96
a 97
b 98
...
o 111
p 112
q 113
r 114
s 115
...
This means, if we sort without adjusting (sortByUnicodeDecimalNumbers = true), in ascending order, the letter b (98 - small) would be after S (83 - Capital).
By disabling sortByUnicodeDecimalNumbers, Capital letters are intermediate transformed to str.lower() after which the Unicode Decimal number is retrieved from the small number instead of the capital number. For example S (83) -> s (115), after which the number 115 is used to sort instead of 83.
Example of usage (besides the included table example):
Pine Script®
🔸 Methods/functions
method toFont(fromText, font)
toFont : Transforms text into the selected font
Namespace types: series string, simple string, input string, const string
Parameters:
fromText (string)
font (string)
Returns: `fromText` transformed to desired `font`
method toCase(fromText, case)
toCase : formats text to snake_case, UPPER SNAKE_CASE, kebab-case, camelCase or PascalCase
Namespace types: series string, simple string, input string, const string
Parameters:
fromText (string)
case (string)
Returns: `fromText` formatted to desired `case`
method sort(strings, order, sortByUnicodeDecimalNumbers)
sort : sorts an array of strings, ascending/descending and by Unicode Decimal numbers or not.
Namespace types: array<string>
Parameters:
strings (array<string>)
order (string)
sortByUnicodeDecimalNumbers (bool)
Returns: Sorted array of strings
library to format text in different fonts or cases plus a sort function.
🔸 Credits and Usage
This library is inspired by the work of three authors (in chronological order of publication date):
🔹 Fonts
Besides extra added font options, the toFont(fromText, font) method uses a different technique. On the first runtime bar (whether it is barstate.isfirst, barstate.islast, or between) regular letters and numbers and mapped with the chosen font. After this, each character is replaced using the build-in key - value pair map function.
Also an enum Efont is included.
Note: Some fonts are not complete, for example there isn't a replacement for every character in Superscript/Subscript.
Example of usage (besides the included table example):
import fikira/Text/1 as t
i_font = input.enum(t.Efont.Blocks)
if barstate.islast
sentence = "this sentence contains words"
label.new(bar_index, 0, t.toFont(fromText = sentence, font = str.tostring(i_font)), style=label.style_label_lower_right)
label.new(bar_index, 0, t.toFont(fromText = sentence, font = "Circled" ), style=label.style_label_lower_left )
label.new(bar_index, 0, t.toFont(fromText = sentence, font = "Wiggly" ), style=label.style_label_upper_right)
label.new(bar_index, 0, t.toFont(fromText = sentence, font = "Upside Latin" ), style=label.style_label_upper_left )
🔹 Cases
The script includes a toCase(fromText, case) method to transform text into snake_case, UPPER SNAKE_CASE, kebab-case, camelCase or PascalCase, as well as an enum Ecase.
Example of usage (besides the included table example):
import fikira/Text/1 as t
i_case = input.enum(t.Ecase.camel)
if barstate.islast
sentence = "this sentence contains words"
label.new(bar_index, 0, t.toCase(fromText = sentence, case = str.tostring(i_case)), style=label.style_label_lower_right)
label.new(bar_index, 0, t.toCase(fromText = sentence, case = "snake_case" ), style=label.style_label_lower_left )
label.new(bar_index, 0, t.toCase(fromText = sentence, case = "PascalCase" ), style=label.style_label_upper_right)
label.new(bar_index, 0, t.toCase(fromText = sentence, case = "SNAKE_CASE" ), style=label.style_label_upper_left )
🔹 Sort
The sort(strings, order, sortByUnicodeDecimalNumbers) method returns a sorted array of strings.
- strings: array of strings, for example
Pine Script® words = array.from("Aword", "beyond", "Space", "salt", "pepper", "swing", "someThing", "otherThing", "12345", "_firstWord") - order: "asc" / "desc" (ascending / descending)
- sortByUnicodeDecimalNumbers: true/false; default = false
_____
• sortByUnicodeDecimalNumbers: every Unicode character is linked to a Unicode Decimal number (wikipedia.org/wiki/List_of_Unicode_characters), for example:
1 49
2 50
3 51
...
A 65
B 66
...
S 83
...
_ 95
` 96
a 97
b 98
...
o 111
p 112
q 113
r 114
s 115
...
This means, if we sort without adjusting (sortByUnicodeDecimalNumbers = true), in ascending order, the letter b (98 - small) would be after S (83 - Capital).
By disabling sortByUnicodeDecimalNumbers, Capital letters are intermediate transformed to str.lower() after which the Unicode Decimal number is retrieved from the small number instead of the capital number. For example S (83) -> s (115), after which the number 115 is used to sort instead of 83.
Example of usage (besides the included table example):
import fikira/Text/1 as t
if barstate.islast
aWords = array.from("Aword", "beyond", "Space", "salt", "pepper", "swing", "someThing", "otherThing", "12345", "_firstWord")
label.new(bar_index, 0, str.tostring(t.sort(strings= aWords, order = 'asc' , sortByUnicodeDecimalNumbers = false)), style=label.style_label_lower_right)
label.new(bar_index, 0, str.tostring(t.sort(strings= aWords, order = 'desc', sortByUnicodeDecimalNumbers = false)), style=label.style_label_lower_left )
label.new(bar_index, 0, str.tostring(t.sort(strings= aWords, order = 'asc' , sortByUnicodeDecimalNumbers = true )), style=label.style_label_upper_right)
label.new(bar_index, 0, str.tostring(t.sort(strings= aWords, order = 'desc', sortByUnicodeDecimalNumbers = true )), style=label.style_label_upper_left )
🔸 Methods/functions
method toFont(fromText, font)
toFont : Transforms text into the selected font
Namespace types: series string, simple string, input string, const string
Parameters:
fromText (string)
font (string)
Returns: `fromText` transformed to desired `font`
method toCase(fromText, case)
toCase : formats text to snake_case, UPPER SNAKE_CASE, kebab-case, camelCase or PascalCase
Namespace types: series string, simple string, input string, const string
Parameters:
fromText (string)
case (string)
Returns: `fromText` formatted to desired `case`
method sort(strings, order, sortByUnicodeDecimalNumbers)
sort : sorts an array of strings, ascending/descending and by Unicode Decimal numbers or not.
Namespace types: array<string>
Parameters:
strings (array<string>)
order (string)
sortByUnicodeDecimalNumbers (bool)
Returns: Sorted array of strings
Pine腳本庫
秉持 TradingView 一貫的共享精神,作者將此 Pine 程式碼發佈為開源庫,讓社群中的其他 Pine 程式設計師能夠重複使用。向作者致敬!您可以在私人專案或其他開源發佈中使用此庫,但在公開發佈中重複使用該程式碼需遵守社群規範。
Who are PineCoders?
tradingview.com/chart/SSP/yW5eOqtm-Who-are-PineCoders/
TG Pine Script® Q&A: t.me/PineCodersQA
- We cannot control our emotions,
but we can control our keyboard -
tradingview.com/chart/SSP/yW5eOqtm-Who-are-PineCoders/
TG Pine Script® Q&A: t.me/PineCodersQA
- We cannot control our emotions,
but we can control our keyboard -
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。
Pine腳本庫
秉持 TradingView 一貫的共享精神,作者將此 Pine 程式碼發佈為開源庫,讓社群中的其他 Pine 程式設計師能夠重複使用。向作者致敬!您可以在私人專案或其他開源發佈中使用此庫,但在公開發佈中重複使用該程式碼需遵守社群規範。
Who are PineCoders?
tradingview.com/chart/SSP/yW5eOqtm-Who-are-PineCoders/
TG Pine Script® Q&A: t.me/PineCodersQA
- We cannot control our emotions,
but we can control our keyboard -
tradingview.com/chart/SSP/yW5eOqtm-Who-are-PineCoders/
TG Pine Script® Q&A: t.me/PineCodersQA
- We cannot control our emotions,
but we can control our keyboard -
免責聲明
這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。