mirror of
https://github.com/ManyakRus/starter.git
synced 2025-11-26 23:10:42 +02:00
сделал stringSplitBylength_WithLastWord1()
This commit is contained in:
@@ -1788,6 +1788,13 @@ func StringSplitBylength(s string, n int) []string {
|
||||
sub := ""
|
||||
subs := []string{}
|
||||
|
||||
//весь текст меньше n
|
||||
if len(s) <= n {
|
||||
subs = append(subs, s)
|
||||
return subs
|
||||
}
|
||||
|
||||
//
|
||||
runes := bytes.Runes([]byte(s))
|
||||
l := len(runes)
|
||||
for i, r := range runes {
|
||||
@@ -1834,6 +1841,13 @@ func stringSplitBylength_WithLastWord1(s []rune, n int, LastWord rune) ([]rune,
|
||||
length := MinInt(n, length1)
|
||||
Otvet = runes[:length]
|
||||
|
||||
//весь текст меньше n
|
||||
if len(s) <= n {
|
||||
Otvet = append(Otvet, s...)
|
||||
return Otvet, len(s)
|
||||
}
|
||||
|
||||
//
|
||||
for i := length; i > 0; i-- {
|
||||
if runes[i-1] == LastWord {
|
||||
pos1 = i
|
||||
|
||||
@@ -1552,6 +1552,14 @@ func TestStringSplitBylength_WithLastWord(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringSplitBylength_WithLastWord2(t *testing.T) {
|
||||
Text1 := "Покупка RU000A10A9Z1 (https://www.tbank.ru/invest/bonds/RU000A10A9Z1)\nМагнит БО-004Р-05\nКоличество: 1\nСумма: 1_035.10 руб.\nЦена: 103.51% = 1_035.10 руб.\nПроцент годовых: 23.52%"
|
||||
MassOtvet := StringSplitBylength_WithLastWord(Text1, 4000, '\n')
|
||||
if MassOtvet[0] != "Приве" {
|
||||
//t.Errorf("Expected 'Приве', but got %s", MassOtvet[0])
|
||||
}
|
||||
}
|
||||
|
||||
func TestRound_Float64_WithPrecision(t *testing.T) {
|
||||
Otvet := Round_Float64_WithPrecision(1.11, 1)
|
||||
if Otvet != 1.1 {
|
||||
|
||||
Reference in New Issue
Block a user