From 112bebcddf99d5187ede8ebbe765abc75373c4f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Mon, 24 Apr 2017 22:37:49 +0200 Subject: [PATCH] core: add a way to count the suffix length in max chars displayed in cut of string ("cut:" and "cutscr:") (closes #963) The format to use is one of: - ${cut:+max,suffix,string} - ${cutscr:+max,suffix,string} With the "+" before max, WeeChat ensures there are at most "max" chars in output, including the length of suffix string. --- doc/de/autogen/user/weechat_commands.adoc | 107 +++++++++++----------- doc/en/autogen/user/weechat_commands.adoc | 7 +- doc/en/weechat_plugin_api.en.adoc | 12 ++- doc/fr/autogen/user/weechat_commands.adoc | 7 +- doc/fr/weechat_plugin_api.fr.adoc | 12 ++- doc/it/autogen/user/weechat_commands.adoc | 7 +- doc/it/weechat_plugin_api.it.adoc | 12 ++- doc/ja/autogen/user/weechat_commands.adoc | 91 +++++++++--------- doc/ja/weechat_plugin_api.ja.adoc | 14 ++- doc/pl/autogen/user/weechat_commands.adoc | 7 +- po/cs.po | 12 ++- po/de.po | 13 ++- po/es.po | 12 ++- po/fr.po | 21 +++-- po/hu.po | 12 ++- po/it.po | 12 ++- po/ja.po | 13 ++- po/pl.po | 12 ++- po/pt.po | 12 ++- po/pt_BR.po | 12 ++- po/ru.po | 12 ++- po/tr.po | 12 ++- po/weechat.pot | 12 ++- src/core/wee-command.c | 9 +- src/core/wee-eval.c | 9 +- src/core/wee-string.c | 25 ++++- src/core/wee-string.h | 4 +- tests/unit/core/test-eval.cpp | 36 ++++++++ 28 files changed, 331 insertions(+), 195 deletions(-) diff --git a/doc/de/autogen/user/weechat_commands.adoc b/doc/de/autogen/user/weechat_commands.adoc index aa3bca5c7..21943eca3 100644 --- a/doc/de/autogen/user/weechat_commands.adoc +++ b/doc/de/autogen/user/weechat_commands.adoc @@ -257,54 +257,54 @@ infolists: zeigt Information über die Infolists an /eval [-n|-s] [-n] -c - -n: gibt das Ergebnis aus, ohne das dieses in den Buffer gesendet wird (debug Modus) - -s: teilt Ausdrücke bevor sie evaluiert werden (mehrere Befehle können durch Semikolon getrennt werden) - -c: Auswertung als Bedingung: nutzt Operatoren und runde Klammern, Rückgabewert als Boolean-Wert ("0" oder "1") -expression: Ausdruck welcher verarbeitet werden soll. Variablen im Format ${variable} werden ersetzt (siehe unten); mehrere Befehle werden durch ein Semikolon voneinander getrennt - operator: ein logischer oder vergleichender Operand: - - logische Operanden: - && boolean "und" - || boolean "oder" - - vergleichende Operanden: - == gleich - != ungleich - <= kleiner oder gleich - < kleiner - >= größer oder gleich - > größer - =~ stimmt mit regulärem POSIX Ausdruck überein - !~ stimmt NICHT mit regulärem POSIX Ausdruck überein + -n: display result without sending it to buffer (debug mode) + -s: split expression before evaluating it (many commands can be separated by semicolons) + -c: evaluate as condition: use operators and parentheses, return a boolean value ("0" or "1") +expression: expression to evaluate, variables with format ${variable} are replaced (see below); many commands can be separated by semicolons + operator: a logical or comparison operator: + - logical operators: + && boolean "and" + || boolean "or" + - comparison operators: + == equal + != not equal + <= less or equal + < less + >= greater or equal + > greater + =~ is matching POSIX extended regex + !~ is NOT matching POSIX extended regex -Ein Ausdruck gilt als "wahr" sofern das Ergebnis weder NULL, leer und von "0" abweichend ist. -Der Vergleich findet zwischen zwei Integer Werten statt, sofern die beiden Ausdrücke gültige Integer-Werte sind. -Um einen Vergleich zwischen zwei Zeichenketten zu erzwingen, müssen die Ausdrücke in Anführungszeichen gesetzt werden, zum Beispiel: +An expression is considered as "true" if it is not NULL, not empty, and different from "0". +The comparison is made using integers if the two expressions are valid integers. +To force a string comparison, add double quotes around each expression, for example: 50 > 100 ==> 0 "50" > "100" ==> 1 -Einige Variablen werden im Ausdruck, mittels der Formatierung ${Variable}, ersetzt. Mögliche Variablen sind, nach Reihenfolge ihrer Priorität: - 1. eine evaluierte Teilzeichenkette (Format: "eval:xxx") - 2. eine Zeichenkette mit Escapesequenzen (Format: "esc:xxx" oder "\xxx") - 3. Zeichen welche in einer Zeichenkette nicht dargestellt werden sollen (Format: "hide:Zeichen,Zeichenkette") - 4. eine Zeichenkette mit einer maximalen Anzahl an Zeichen (Format: "cut:Max,Suffix,Zeichenkette") - oder maximale Anzahl an Zeichen die auf dem Bildschirm angezeigt werden sollen (Format: "cutscr:max,Suffix,Zeichenkette") - 5. eine Farbe (Format: "color:xxx", siehe "Anleitung für API Erweiterung", Funktion "color")\n - 6. eine Info (Format: "info:name,arguments", Argumente sind optional) - 7. aktuelles Datum/Uhrzeit (Format: "date" oder "date:format") - 8. eine Umgebungsvariable (Format: "env:XXX") - 9. ein Dreifachoperand (Format: "if:Bedingung?Wert_falls_wahr:Wert_falls_unwahr") - 10. eine Option (Format: "file.section.option") - 11. der Name einer lokalen Variablen eines Buffer - 12. ein hdata Name/Variable (der Wert wird automatisch als Zeichenkette konvertiert), standardmäßig wird für "window" und "buffer" das aktuelle Fenster/Buffer verwendet. -Das Format für hdata kann wie folgt aufgebaut sein: - hdata.var1.var2...: startet mit hdata (der Pointer muss bekannt sein) und fragt eine Variable nach der anderen ab (weitere hdata können folgen) - hdata[list].var1.var2...: startet hdata mittels einer Liste, zum Beispiel: - ${buffer[gui_buffers].full_name}: der vollständige Name des ersten Buffers, in der verknüpften Liste aller Buffer - ${plugin[weechat_plugins].name}: Name der ersten Erweiterung, in der verknüpften Liste aller Erweiterungen - hdata[pointer].var1.var2...: startet hdata mittels einem Pointer, zum Beispiel: - ${buffer[0x1234abcd].full_name}: vollständiger Name eines Buffers und des dazugehörigen Pointers (kann in triggern benutzt werden) -Die vorhandenen Namen für hdata und Variablen sind in der "Anleitung für API Erweiterung", Bereich "weechat_hdata_get". beschrieben +Some variables are replaced in expression, using the format ${variable}, variable can be, by order of priority: + 1. an evaluated sub-string (format: "eval:xxx") + 2. a string with escaped chars (format: "esc:xxx" or "\xxx") + 3. a string with chars to hide (format: "hide:char,string") + 4. a string with max chars (format: "cut:max,suffix,string" or "cut:+max,suffix,string") + or max chars displayed on screen (format: "cutscr:max,suffix,string" or "cutscr:+max,suffix,string") + 5. a color (format: "color:xxx", see "Plugin API reference", function "color") + 6. an info (format: "info:name,arguments", arguments are optional) + 7. current date/time (format: "date" or "date:format") + 8. an environment variable (format: "env:XXX") + 9. a ternary operator (format: "if:condition?value_if_true:value_if_false") + 10. an option (format: "file.section.option") + 11. a local variable in buffer + 12. a hdata name/variable (the value is automatically converted to string), by default "window" and "buffer" point to current window/buffer. +Format for hdata can be one of following: + hdata.var1.var2...: start with a hdata (pointer must be known), and ask variables one after one (other hdata can be followed) + hdata[list].var1.var2...: start with a hdata using a list, for example: + ${buffer[gui_buffers].full_name}: full name of first buffer in linked list of buffers + ${plugin[weechat_plugins].name}: name of first plugin in linked list of plugins + hdata[pointer].var1.var2...: start with a hdata using a pointer, for example: + ${buffer[0x1234abcd].full_name}: full name of the buffer with this pointer (can be used in triggers) +For name of hdata and variables, please look at "Plugin API reference", function "weechat_hdata_get". -Beispiele (einfache Zeichenketten): +Examples (simple strings): /eval -n ${info:version} ==> 0.4.3 /eval -n ${env:HOME} ==> /home/user /eval -n ${weechat.look.scroll_amount} ==> 3 @@ -314,19 +314,20 @@ Beispiele (einfache Zeichenketten): /eval -n ${window.buffer.number} ==> 1 /eval -n ${\t} ==> /eval -n ${hide:-,${relay.network.password}} ==> -------- - /eval -n ${cut:2,+,test} ==> te+ + /eval -n ${cut:3,+,test} ==> tes+ + /eval -n ${cut:+3,+,test} ==> te+ /eval -n ${date:%H:%M:%S} ==> 07:46:40 /eval -n ${if:${info:term_width}>80?big:small} ==> big -Beispiele (Bedingungen): - /eval -n -c ${window.buffer.number} > 2 ==> 0 - /eval -n -c ${window.win_width} > 100 ==> 1 - /eval -n -c (8 > 12) || (5 > 2) ==> 1 - /eval -n -c (8 > 12) && (5 > 2) ==> 0 - /eval -n -c abcd =~ ^ABC ==> 1 - /eval -n -c abcd =~ (?-i)^ABC ==> 0 - /eval -n -c abcd =~ (?-i)^abc ==> 1 - /eval -n -c abcd !~ abc ==> 0 +Examples (conditions): + /eval -n -c ${window.buffer.number} > 2 ==> 0 + /eval -n -c ${window.win_width} > 100 ==> 1 + /eval -n -c (8 > 12) || (5 > 2) ==> 1 + /eval -n -c (8 > 12) && (5 > 2) ==> 0 + /eval -n -c abcd =~ ^ABC ==> 1 + /eval -n -c abcd =~ (?-i)^ABC ==> 0 + /eval -n -c abcd =~ (?-i)^abc ==> 1 + /eval -n -c abcd !~ abc ==> 0 ---- [[command_weechat_filter]] diff --git a/doc/en/autogen/user/weechat_commands.adoc b/doc/en/autogen/user/weechat_commands.adoc index ab745d4ff..aaa5bc7e7 100644 --- a/doc/en/autogen/user/weechat_commands.adoc +++ b/doc/en/autogen/user/weechat_commands.adoc @@ -285,8 +285,8 @@ Some variables are replaced in expression, using the format ${variable}, variabl 1. an evaluated sub-string (format: "eval:xxx") 2. a string with escaped chars (format: "esc:xxx" or "\xxx") 3. a string with chars to hide (format: "hide:char,string") - 4. a string with max chars (format: "cut:max,suffix,string") - or max chars displayed on screen (format: "cutscr:max,suffix,string") + 4. a string with max chars (format: "cut:max,suffix,string" or "cut:+max,suffix,string") + or max chars displayed on screen (format: "cutscr:max,suffix,string" or "cutscr:+max,suffix,string") 5. a color (format: "color:xxx", see "Plugin API reference", function "color") 6. an info (format: "info:name,arguments", arguments are optional) 7. current date/time (format: "date" or "date:format") @@ -314,7 +314,8 @@ Examples (simple strings): /eval -n ${window.buffer.number} ==> 1 /eval -n ${\t} ==> /eval -n ${hide:-,${relay.network.password}} ==> -------- - /eval -n ${cut:2,+,test} ==> te+ + /eval -n ${cut:3,+,test} ==> tes+ + /eval -n ${cut:+3,+,test} ==> te+ /eval -n ${date:%H:%M:%S} ==> 07:46:40 /eval -n ${if:${info:term_width}>80?big:small} ==> big diff --git a/doc/en/weechat_plugin_api.en.adoc b/doc/en/weechat_plugin_api.en.adoc index 461655410..2d3091af6 100644 --- a/doc/en/weechat_plugin_api.en.adoc +++ b/doc/en/weechat_plugin_api.en.adoc @@ -2043,19 +2043,27 @@ expanded to last): `+********+` | `+${cut:max,suffix,string}+` + + `+${cut:+max,suffix,string}+` + (_WeeChat ≥ 1.8_) | - String with `max` chars, and optional `suffix` if string is cut. | + String with `max` chars, and optional `suffix` if string is cut. + + With the format `+max`, the suffix is counted in max length. | `+${cut:4,…,this is a test}+` + + `+${cut:+4,…,this is a test}+` + `+${cut:2,>>,こんにちは世界}+` | `+this…+` + + `+t…+` + `+こん>>+` | `+${cutscr:max,suffix,string}+` + + `+${cutscr:+max,suffix,string}+` + (_WeeChat ≥ 1.8_) | - String with `max` chars displayed on screen, and optional `suffix` if string is cut. | + String with `max` chars displayed on screen, and optional `suffix` if string is cut. + + With the format `+max`, the suffix is counted in max length. | `+${cutscr:4,…,this is a test}+` + + `+${cutscr:+4,…,this is a test}+` + `+${cutscr:2,>>,こんにちは世界}+` | `+this…+` + + `+thi…+` + `+こ>>+` | `+${re:N}+` + diff --git a/doc/fr/autogen/user/weechat_commands.adoc b/doc/fr/autogen/user/weechat_commands.adoc index 9ea319c05..ddc286543 100644 --- a/doc/fr/autogen/user/weechat_commands.adoc +++ b/doc/fr/autogen/user/weechat_commands.adoc @@ -285,8 +285,8 @@ Des variables sont remplacées dans l'expression, en utilisant le format ${varia 1. une sous-chaîne évaluée (format : "eval:xxx") 2. une chaîne avec les caractères échappés (format : "esc:xxx" ou "\xxx") 3. une chaîne avec des caractères à cacher (format : "hide:caractère,chaîne") - 4. une chaîne avec un maximum de caractères (format : "cut:max,suffixe,chaîne") - ou un maximum de caractères affichés à l'écran (format : "cutscr:max,suffixe,chaîne") + 4. une chaîne avec un maximum de caractères (format : "cut:max,suffixe,chaîne" ou "cut:+max,suffixe,chaîne") + ou un maximum de caractères affichés à l'écran (format : "cutscr:max,suffixe,chaîne" ou "cutscr:+max,suffixe,chaîne") 5. une couleur (format : "color:xxx", voir la "Référence API extension", fonction "color") 6. une info (format : "info:nom,paramètres", les paramètres sont optionnels) 7. la date/heure courante (format : "date" ou "date:format") @@ -314,7 +314,8 @@ Exemples (chaînes simples) : /eval -n ${window.buffer.number} ==> 1 /eval -n ${\t} ==> /eval -n ${hide:-,${relay.network.password}} ==> -------- - /eval -n ${cut:2,+,test} ==> te+ + /eval -n ${cut:3,+,test} ==> tes+ + /eval -n ${cut:+3,+,test} ==> te+ /eval -n ${date:%H:%M:%S} ==> 07:46:40 /eval -n ${if:${info:term_width}>80?big:small} ==> big diff --git a/doc/fr/weechat_plugin_api.fr.adoc b/doc/fr/weechat_plugin_api.fr.adoc index 35586656f..6b1c94e25 100644 --- a/doc/fr/weechat_plugin_api.fr.adoc +++ b/doc/fr/weechat_plugin_api.fr.adoc @@ -2086,19 +2086,27 @@ première étendue à la dernière) : `+************+` | `+${cut:max,suffixe,chaîne}+` + + `+${cut:+max,suffixe,chaîne}+` + (_WeeChat ≥ 1.8_) | - Chaîne avec `max` caractères, et un `suffixe` facultatif si la chaîne est coupée. | + Chaîne avec `max` caractères, et un `suffixe` facultatif si la chaîne est coupée. + + Avec le format `+max`, le suffixe est compté dans la longueur maximale. | `+${cut:4,…,ceci est un test}+` + + `+${cut:+4,…,ceci est un test}+` + `+${cut:2,>>,こんにちは世界}+` | `+ceci…+` + + `+c…+` + `+こん>>+` | `+${cutscr:max,suffixe,chaîne}+` + + `+${cutscr:+max,suffixe,chaîne}+` + (_WeeChat ≥ 1.8_) | - Chaîne avec `max` caractères affichés à l'écran, et un `suffixe` facultatif si la chaîne est coupée. | + Chaîne avec `max` caractères affichés à l'écran, et un `suffixe` facultatif si la chaîne est coupée. + + Avec le format `+max`, le suffixe est compté dans la longueur maximale. | `+${cutscr:4,…,ceci est un test}+` + + `+${cutscr:+4,…,ceci est un test}+` + `+${cutscr:2,>>,こんにちは世界}+` | `+ceci…+` + + `+cec…+` + `+こ>>+` | `+${re:N}+` + diff --git a/doc/it/autogen/user/weechat_commands.adoc b/doc/it/autogen/user/weechat_commands.adoc index 1e50ea5f1..fdffcf0ce 100644 --- a/doc/it/autogen/user/weechat_commands.adoc +++ b/doc/it/autogen/user/weechat_commands.adoc @@ -285,8 +285,8 @@ Some variables are replaced in expression, using the format ${variable}, variabl 1. an evaluated sub-string (format: "eval:xxx") 2. a string with escaped chars (format: "esc:xxx" or "\xxx") 3. a string with chars to hide (format: "hide:char,string") - 4. a string with max chars (format: "cut:max,suffix,string") - or max chars displayed on screen (format: "cutscr:max,suffix,string") + 4. a string with max chars (format: "cut:max,suffix,string" or "cut:+max,suffix,string") + or max chars displayed on screen (format: "cutscr:max,suffix,string" or "cutscr:+max,suffix,string") 5. a color (format: "color:xxx", see "Plugin API reference", function "color") 6. an info (format: "info:name,arguments", arguments are optional) 7. current date/time (format: "date" or "date:format") @@ -314,7 +314,8 @@ Examples (simple strings): /eval -n ${window.buffer.number} ==> 1 /eval -n ${\t} ==> /eval -n ${hide:-,${relay.network.password}} ==> -------- - /eval -n ${cut:2,+,test} ==> te+ + /eval -n ${cut:3,+,test} ==> tes+ + /eval -n ${cut:+3,+,test} ==> te+ /eval -n ${date:%H:%M:%S} ==> 07:46:40 /eval -n ${if:${info:term_width}>80?big:small} ==> big diff --git a/doc/it/weechat_plugin_api.it.adoc b/doc/it/weechat_plugin_api.it.adoc index a0a5bbc88..647a392e4 100644 --- a/doc/it/weechat_plugin_api.it.adoc +++ b/doc/it/weechat_plugin_api.it.adoc @@ -2121,19 +2121,27 @@ expanded to last): `+********+` | `+${cut:max,suffix,string}+` + + `+${cut:+max,suffix,string}+` + (_WeeChat ≥ 1.8_) | - String with `max` chars, and optional `suffix` if string is cut. | + String with `max` chars, and optional `suffix` if string is cut. + + With the format `+max`, the suffix is counted in max length. | `+${cut:4,…,this is a test}+` + + `+${cut:+4,…,this is a test}+` + `+${cut:2,>>,こんにちは世界}+` | `+this…+` + + `+t…+` + `+こん>>+` | `+${cutscr:max,suffix,string}+` + + `+${cutscr:+max,suffix,string}+` + (_WeeChat ≥ 1.8_) | - String with `max` chars displayed on screen, and optional `suffix` if string is cut. | + String with `max` chars displayed on screen, and optional `suffix` if string is cut. + + With the format `+max`, the suffix is counted in max length. | `+${cutscr:4,…,this is a test}+` + + `+${cutscr:+4,…,this is a test}+` + `+${cutscr:2,>>,こんにちは世界}+` | `+this…+` + + `+thi…+` + `+こ>>+` | `+${re:N}+` + diff --git a/doc/ja/autogen/user/weechat_commands.adoc b/doc/ja/autogen/user/weechat_commands.adoc index 8cc20fb79..08e1580b2 100644 --- a/doc/ja/autogen/user/weechat_commands.adoc +++ b/doc/ja/autogen/user/weechat_commands.adoc @@ -257,54 +257,54 @@ infolists: インフォリストに関する情報を表示 /eval [-n|-s] [-n] -c - -n: 結果をバッファに送信せずに表示 (デバッグモード) - -s: 評価前に式を分割する (複数のコマンドを指定する場合はセミコロンで区切ってください) - -c: 条件として評価: 演算子と括弧をを使い、ブール値 ("0" または "1") を返します -expression: 評価する式、${variable} 型の書式の変数は置換されます (以下を参照); 複数のコマンドを指定する場合はセミコロンで区切ってください - operator: 論理演算子や比較演算子: - - 論理演算子: - && ブール演算の "and" - || ブール演算の "or" - - 比較演算子: - == 等しい - != 等しくない - <= 以下 - < より少ない - >= 以上 - > より大きい - =~ 正規表現にマッチ - !~ 正規表現にマッチしない + -n: display result without sending it to buffer (debug mode) + -s: split expression before evaluating it (many commands can be separated by semicolons) + -c: evaluate as condition: use operators and parentheses, return a boolean value ("0" or "1") +expression: expression to evaluate, variables with format ${variable} are replaced (see below); many commands can be separated by semicolons + operator: a logical or comparison operator: + - logical operators: + && boolean "and" + || boolean "or" + - comparison operators: + == equal + != not equal + <= less or equal + < less + >= greater or equal + > greater + =~ is matching POSIX extended regex + !~ is NOT matching POSIX extended regex -式が NULL でない場合、空でない場合、"0" でない場合、式は "真" と評価されます。 -両方の式が有効な整数である場合、比較は整数を使って行われます。 -文字列比較を強制するには、それぞれの式をダブルクォートで囲みます、例: +An expression is considered as "true" if it is not NULL, not empty, and different from "0". +The comparison is made using integers if the two expressions are valid integers. +To force a string comparison, add double quotes around each expression, for example: 50 > 100 ==> 0 "50" > "100" ==> 1 -式中の ${variable} 型の書式の変数は置換されます。変数は以下の優先順位に従います: - 1. 評価済みのサブ文字列 (書式: "eval:xxx") - 2. エスケープ文字を含む文字列 (書式: "esc:xxx" または "\xxx") - 3. 隠す文字を含む文字列 (書式: "hide:char,string") - 4. 最大文字数を指定した文字列 (書式: "cut:max,suffix,string") - または最大文字表示幅を指定した文字列 (書式: "cutscr:max,suffix,string") - 5. 色 (書式: "color:xxx"、"プラグイン API リファレンス" の "color" 関数を参照してください) - 6. 情報 (書式: "info:name,arguments"、arguments は任意) - 7. 現在の日付/時刻 (書式: "date" または "date:format") - 8. 環境変数 (書式: "env:XXX") - 9. 三項演算子 (書式: "if:condition?value_if_true:value_if_false") - 10. オプション (書式: "file.section.option") - 11. バッファのローカル変数 - 12. hdata の名前/変数 (値は自動的に文字列に変換されます)、デフォルトでは "window" と "buffer" は現在のウィンドウ/バッファを指します。 -hdata の書式は以下の 1 つです: - hdata.var1.var2...: hdata (ポインタは既知) で開始し、1 個ずつ変数を続ける (他の hdata を続けることも可能) - hdata[list].var1.var2...: リストを使う hdata で開始する、例: - ${buffer[gui_buffers].full_name}: バッファリストにリンクされた最初のバッファのフルネーム - ${plugin[weechat_plugins].name}: プラグインリストにリンクされた最初のプラグインの名前 - hdata[pointer].var1.var2...: ポインタを使う hdata で開始する、例: - ${buffer[0x1234abcd].full_name}: 与えたポインタを持つバッファの完全な名前 (トリガ中で使うことが可能です) -hdata と変数の名前については、"プラグイン API リファレンス" の "weechat_hdata_get" 関数を参照してください。 +Some variables are replaced in expression, using the format ${variable}, variable can be, by order of priority: + 1. an evaluated sub-string (format: "eval:xxx") + 2. a string with escaped chars (format: "esc:xxx" or "\xxx") + 3. a string with chars to hide (format: "hide:char,string") + 4. a string with max chars (format: "cut:max,suffix,string" or "cut:+max,suffix,string") + or max chars displayed on screen (format: "cutscr:max,suffix,string" or "cutscr:+max,suffix,string") + 5. a color (format: "color:xxx", see "Plugin API reference", function "color") + 6. an info (format: "info:name,arguments", arguments are optional) + 7. current date/time (format: "date" or "date:format") + 8. an environment variable (format: "env:XXX") + 9. a ternary operator (format: "if:condition?value_if_true:value_if_false") + 10. an option (format: "file.section.option") + 11. a local variable in buffer + 12. a hdata name/variable (the value is automatically converted to string), by default "window" and "buffer" point to current window/buffer. +Format for hdata can be one of following: + hdata.var1.var2...: start with a hdata (pointer must be known), and ask variables one after one (other hdata can be followed) + hdata[list].var1.var2...: start with a hdata using a list, for example: + ${buffer[gui_buffers].full_name}: full name of first buffer in linked list of buffers + ${plugin[weechat_plugins].name}: name of first plugin in linked list of plugins + hdata[pointer].var1.var2...: start with a hdata using a pointer, for example: + ${buffer[0x1234abcd].full_name}: full name of the buffer with this pointer (can be used in triggers) +For name of hdata and variables, please look at "Plugin API reference", function "weechat_hdata_get". -例 (単純な文字列): +Examples (simple strings): /eval -n ${info:version} ==> 0.4.3 /eval -n ${env:HOME} ==> /home/user /eval -n ${weechat.look.scroll_amount} ==> 3 @@ -314,11 +314,12 @@ hdata と変数の名前については、"プラグイン API リファレン /eval -n ${window.buffer.number} ==> 1 /eval -n ${\t} ==> /eval -n ${hide:-,${relay.network.password}} ==> -------- - /eval -n ${cut:2,+,test} ==> te+ + /eval -n ${cut:3,+,test} ==> tes+ + /eval -n ${cut:+3,+,test} ==> te+ /eval -n ${date:%H:%M:%S} ==> 07:46:40 /eval -n ${if:${info:term_width}>80?big:small} ==> big -例 (条件): +Examples (conditions): /eval -n -c ${window.buffer.number} > 2 ==> 0 /eval -n -c ${window.win_width} > 100 ==> 1 /eval -n -c (8 > 12) || (5 > 2) ==> 1 diff --git a/doc/ja/weechat_plugin_api.ja.adoc b/doc/ja/weechat_plugin_api.ja.adoc index 13382461f..62a648055 100644 --- a/doc/ja/weechat_plugin_api.ja.adoc +++ b/doc/ja/weechat_plugin_api.ja.adoc @@ -2048,20 +2048,30 @@ char *weechat_string_eval_expression (const char *expr, `+${hide:*,password}+` | `+********+` +// TRANSLATION MISSING | `+${cut:max,suffix,string}+` + + `+${cut:+max,suffix,string}+` + (_WeeChat バージョン 1.8 以上で利用可_) | - `string` の先頭 `max` 文字とオプションの `suffix` 文字 (`string` の文字数が `max` 文字を超える場合) | + `string` の先頭 `max` 文字とオプションの `suffix` 文字 (`string` の文字数が `max` 文字を超える場合) + + With the format `+max`, the suffix is counted in max length. | `+${cut:4,…,this is a test}+` + + `+${cut:+4,…,this is a test}+` + `+${cut:2,>>,こんにちは世界}+` | `+this…+` + + `+t…+` + `+こん>>+` +// TRANSLATION MISSING | `+${cutscr:max,suffix,string}+` + + `+${cutscr:+max,suffix,string}+` + (_WeeChat バージョン 1.8 以上で利用可_) | - `string` の先頭 `max` 文字 (半角文字幅換算) とオプションの `suffix` 文字 (`string` の文字数が `max` 文字を超える場合) | + `string` の先頭 `max` 文字 (半角文字幅換算) とオプションの `suffix` 文字 (`string` の文字数が `max` 文字を超える場合) + + With the format `+max`, the suffix is counted in max length. | `+${cutscr:4,…,this is a test}+` + + `+${cutscr:+4,…,this is a test}+` + `+${cutscr:2,>>,こんにちは世界}+` | `+this…+` + + `+thi…+` + `+こ>>+` | `+${re:N}+` + diff --git a/doc/pl/autogen/user/weechat_commands.adoc b/doc/pl/autogen/user/weechat_commands.adoc index b85e42d6c..fa6395d45 100644 --- a/doc/pl/autogen/user/weechat_commands.adoc +++ b/doc/pl/autogen/user/weechat_commands.adoc @@ -285,8 +285,8 @@ Some variables are replaced in expression, using the format ${variable}, variabl 1. an evaluated sub-string (format: "eval:xxx") 2. a string with escaped chars (format: "esc:xxx" or "\xxx") 3. a string with chars to hide (format: "hide:char,string") - 4. a string with max chars (format: "cut:max,suffix,string") - or max chars displayed on screen (format: "cutscr:max,suffix,string") + 4. a string with max chars (format: "cut:max,suffix,string" or "cut:+max,suffix,string") + or max chars displayed on screen (format: "cutscr:max,suffix,string" or "cutscr:+max,suffix,string") 5. a color (format: "color:xxx", see "Plugin API reference", function "color") 6. an info (format: "info:name,arguments", arguments are optional) 7. current date/time (format: "date" or "date:format") @@ -314,7 +314,8 @@ Examples (simple strings): /eval -n ${window.buffer.number} ==> 1 /eval -n ${\t} ==> /eval -n ${hide:-,${relay.network.password}} ==> -------- - /eval -n ${cut:2,+,test} ==> te+ + /eval -n ${cut:3,+,test} ==> tes+ + /eval -n ${cut:+3,+,test} ==> te+ /eval -n ${date:%H:%M:%S} ==> 07:46:40 /eval -n ${if:${info:term_width}>80?big:small} ==> big diff --git a/po/cs.po b/po/cs.po index 385437f86..25b18cbc4 100644 --- a/po/cs.po +++ b/po/cs.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2017-04-23 14:44+0200\n" +"POT-Creation-Date: 2017-04-24 22:34+0200\n" "PO-Revision-Date: 2017-01-06 21:59+0100\n" "Last-Translator: Ondřej Súkup \n" "Language-Team: weechat-dev \n" @@ -1471,9 +1471,10 @@ msgid "" " 1. an evaluated sub-string (format: \"eval:xxx\")\n" " 2. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" " 3. a string with chars to hide (format: \"hide:char,string\")\n" -" 4. a string with max chars (format: \"cut:max,suffix,string\")\n" -" or max chars displayed on screen (format: \"cutscr:max,suffix,string" -"\")\n" +" 4. a string with max chars (format: \"cut:max,suffix,string\" or \"cut:" +"+max,suffix,string\")\n" +" or max chars displayed on screen (format: \"cutscr:max,suffix,string\" " +"or \"cutscr:+max,suffix,string\")\n" " 5. a color (format: \"color:xxx\", see \"Plugin API reference\", function " "\"color\")\n" " 6. an info (format: \"info:name,arguments\", arguments are optional)\n" @@ -1511,7 +1512,8 @@ msgid "" " /eval -n ${window.buffer.number} ==> 1\n" " /eval -n ${\\t} ==> \n" " /eval -n ${hide:-,${relay.network.password}} ==> --------\n" -" /eval -n ${cut:2,+,test} ==> te+\n" +" /eval -n ${cut:3,+,test} ==> tes+\n" +" /eval -n ${cut:+3,+,test} ==> te+\n" " /eval -n ${date:%H:%M:%S} ==> 07:46:40\n" " /eval -n ${if:${info:term_width}>80?big:small} ==> big\n" "\n" diff --git a/po/de.po b/po/de.po index 4b1bcf5ae..c9062cccd 100644 --- a/po/de.po +++ b/po/de.po @@ -19,7 +19,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2017-04-23 14:44+0200\n" +"POT-Creation-Date: 2017-04-24 22:34+0200\n" "PO-Revision-Date: 2017-04-24 22:21+0200\n" "Last-Translator: Nils Görs \n" "Language-Team: German \n" @@ -1537,6 +1537,7 @@ msgstr "evaluierter Ausdruck" msgid "[-n|-s] || [-n] -c " msgstr "[-n|-s] || [-n] -c " +#, fuzzy msgid "" " -n: display result without sending it to buffer (debug mode)\n" " -s: split expression before evaluating it (many commands can be " @@ -1573,9 +1574,10 @@ msgid "" " 1. an evaluated sub-string (format: \"eval:xxx\")\n" " 2. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" " 3. a string with chars to hide (format: \"hide:char,string\")\n" -" 4. a string with max chars (format: \"cut:max,suffix,string\")\n" -" or max chars displayed on screen (format: \"cutscr:max,suffix,string" -"\")\n" +" 4. a string with max chars (format: \"cut:max,suffix,string\" or \"cut:" +"+max,suffix,string\")\n" +" or max chars displayed on screen (format: \"cutscr:max,suffix,string\" " +"or \"cutscr:+max,suffix,string\")\n" " 5. a color (format: \"color:xxx\", see \"Plugin API reference\", function " "\"color\")\n" " 6. an info (format: \"info:name,arguments\", arguments are optional)\n" @@ -1613,7 +1615,8 @@ msgid "" " /eval -n ${window.buffer.number} ==> 1\n" " /eval -n ${\\t} ==> \n" " /eval -n ${hide:-,${relay.network.password}} ==> --------\n" -" /eval -n ${cut:2,+,test} ==> te+\n" +" /eval -n ${cut:3,+,test} ==> tes+\n" +" /eval -n ${cut:+3,+,test} ==> te+\n" " /eval -n ${date:%H:%M:%S} ==> 07:46:40\n" " /eval -n ${if:${info:term_width}>80?big:small} ==> big\n" "\n" diff --git a/po/es.po b/po/es.po index c5d6b8aba..1aebd7fa1 100644 --- a/po/es.po +++ b/po/es.po @@ -22,7 +22,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2017-04-23 14:44+0200\n" +"POT-Creation-Date: 2017-04-24 22:34+0200\n" "PO-Revision-Date: 2017-01-06 22:01+0100\n" "Last-Translator: Elián Hanisch \n" "Language-Team: weechat-dev \n" @@ -1503,9 +1503,10 @@ msgid "" " 1. an evaluated sub-string (format: \"eval:xxx\")\n" " 2. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" " 3. a string with chars to hide (format: \"hide:char,string\")\n" -" 4. a string with max chars (format: \"cut:max,suffix,string\")\n" -" or max chars displayed on screen (format: \"cutscr:max,suffix,string" -"\")\n" +" 4. a string with max chars (format: \"cut:max,suffix,string\" or \"cut:" +"+max,suffix,string\")\n" +" or max chars displayed on screen (format: \"cutscr:max,suffix,string\" " +"or \"cutscr:+max,suffix,string\")\n" " 5. a color (format: \"color:xxx\", see \"Plugin API reference\", function " "\"color\")\n" " 6. an info (format: \"info:name,arguments\", arguments are optional)\n" @@ -1543,7 +1544,8 @@ msgid "" " /eval -n ${window.buffer.number} ==> 1\n" " /eval -n ${\\t} ==> \n" " /eval -n ${hide:-,${relay.network.password}} ==> --------\n" -" /eval -n ${cut:2,+,test} ==> te+\n" +" /eval -n ${cut:3,+,test} ==> tes+\n" +" /eval -n ${cut:+3,+,test} ==> te+\n" " /eval -n ${date:%H:%M:%S} ==> 07:46:40\n" " /eval -n ${if:${info:term_width}>80?big:small} ==> big\n" "\n" diff --git a/po/fr.po b/po/fr.po index dc371e74a..7350a083a 100644 --- a/po/fr.po +++ b/po/fr.po @@ -21,8 +21,8 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2017-04-23 14:44+0200\n" -"PO-Revision-Date: 2017-04-23 14:45+0200\n" +"POT-Creation-Date: 2017-04-24 22:34+0200\n" +"PO-Revision-Date: 2017-04-24 22:35+0200\n" "Last-Translator: Sébastien Helleu \n" "Language-Team: weechat-dev \n" "Language: fr\n" @@ -1550,9 +1550,10 @@ msgid "" " 1. an evaluated sub-string (format: \"eval:xxx\")\n" " 2. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" " 3. a string with chars to hide (format: \"hide:char,string\")\n" -" 4. a string with max chars (format: \"cut:max,suffix,string\")\n" -" or max chars displayed on screen (format: \"cutscr:max,suffix,string" -"\")\n" +" 4. a string with max chars (format: \"cut:max,suffix,string\" or \"cut:" +"+max,suffix,string\")\n" +" or max chars displayed on screen (format: \"cutscr:max,suffix,string\" " +"or \"cutscr:+max,suffix,string\")\n" " 5. a color (format: \"color:xxx\", see \"Plugin API reference\", function " "\"color\")\n" " 6. an info (format: \"info:name,arguments\", arguments are optional)\n" @@ -1590,7 +1591,8 @@ msgid "" " /eval -n ${window.buffer.number} ==> 1\n" " /eval -n ${\\t} ==> \n" " /eval -n ${hide:-,${relay.network.password}} ==> --------\n" -" /eval -n ${cut:2,+,test} ==> te+\n" +" /eval -n ${cut:3,+,test} ==> tes+\n" +" /eval -n ${cut:+3,+,test} ==> te+\n" " /eval -n ${date:%H:%M:%S} ==> 07:46:40\n" " /eval -n ${if:${info:term_width}>80?big:small} ==> big\n" "\n" @@ -1644,9 +1646,9 @@ msgstr "" " 3. une chaîne avec des caractères à cacher (format : \"hide:caractère," "chaîne\")\n" " 4. une chaîne avec un maximum de caractères (format : \"cut:max,suffixe," -"chaîne\")\n" +"chaîne\" ou \"cut:+max,suffixe,chaîne\")\n" " ou un maximum de caractères affichés à l'écran (format : \"cutscr:max," -"suffixe,chaîne\")\n" +"suffixe,chaîne\" ou \"cutscr:+max,suffixe,chaîne\")\n" " 5. une couleur (format : \"color:xxx\", voir la \"Référence API extension" "\", fonction \"color\")\n" " 6. une info (format : \"info:nom,paramètres\", les paramètres sont " @@ -1687,7 +1689,8 @@ msgstr "" " /eval -n ${window.buffer.number} ==> 1\n" " /eval -n ${\\t} ==> \n" " /eval -n ${hide:-,${relay.network.password}} ==> --------\n" -" /eval -n ${cut:2,+,test} ==> te+\n" +" /eval -n ${cut:3,+,test} ==> tes+\n" +" /eval -n ${cut:+3,+,test} ==> te+\n" " /eval -n ${date:%H:%M:%S} ==> 07:46:40\n" " /eval -n ${if:${info:term_width}>80?big:small} ==> big\n" "\n" diff --git a/po/hu.po b/po/hu.po index 75a0ed3b7..3406594e1 100644 --- a/po/hu.po +++ b/po/hu.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2017-04-23 14:44+0200\n" +"POT-Creation-Date: 2017-04-24 22:34+0200\n" "PO-Revision-Date: 2017-01-06 22:03+0100\n" "Last-Translator: Andras Voroskoi \n" "Language-Team: weechat-dev \n" @@ -1393,9 +1393,10 @@ msgid "" " 1. an evaluated sub-string (format: \"eval:xxx\")\n" " 2. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" " 3. a string with chars to hide (format: \"hide:char,string\")\n" -" 4. a string with max chars (format: \"cut:max,suffix,string\")\n" -" or max chars displayed on screen (format: \"cutscr:max,suffix,string" -"\")\n" +" 4. a string with max chars (format: \"cut:max,suffix,string\" or \"cut:" +"+max,suffix,string\")\n" +" or max chars displayed on screen (format: \"cutscr:max,suffix,string\" " +"or \"cutscr:+max,suffix,string\")\n" " 5. a color (format: \"color:xxx\", see \"Plugin API reference\", function " "\"color\")\n" " 6. an info (format: \"info:name,arguments\", arguments are optional)\n" @@ -1433,7 +1434,8 @@ msgid "" " /eval -n ${window.buffer.number} ==> 1\n" " /eval -n ${\\t} ==> \n" " /eval -n ${hide:-,${relay.network.password}} ==> --------\n" -" /eval -n ${cut:2,+,test} ==> te+\n" +" /eval -n ${cut:3,+,test} ==> tes+\n" +" /eval -n ${cut:+3,+,test} ==> te+\n" " /eval -n ${date:%H:%M:%S} ==> 07:46:40\n" " /eval -n ${if:${info:term_width}>80?big:small} ==> big\n" "\n" diff --git a/po/it.po b/po/it.po index d6b0f5521..ed3f0ec0f 100644 --- a/po/it.po +++ b/po/it.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2017-04-23 14:44+0200\n" +"POT-Creation-Date: 2017-04-24 22:34+0200\n" "PO-Revision-Date: 2017-01-06 22:04+0100\n" "Last-Translator: Esteban I. Ruiz Moreno \n" "Language-Team: weechat-dev \n" @@ -1486,9 +1486,10 @@ msgid "" " 1. an evaluated sub-string (format: \"eval:xxx\")\n" " 2. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" " 3. a string with chars to hide (format: \"hide:char,string\")\n" -" 4. a string with max chars (format: \"cut:max,suffix,string\")\n" -" or max chars displayed on screen (format: \"cutscr:max,suffix,string" -"\")\n" +" 4. a string with max chars (format: \"cut:max,suffix,string\" or \"cut:" +"+max,suffix,string\")\n" +" or max chars displayed on screen (format: \"cutscr:max,suffix,string\" " +"or \"cutscr:+max,suffix,string\")\n" " 5. a color (format: \"color:xxx\", see \"Plugin API reference\", function " "\"color\")\n" " 6. an info (format: \"info:name,arguments\", arguments are optional)\n" @@ -1526,7 +1527,8 @@ msgid "" " /eval -n ${window.buffer.number} ==> 1\n" " /eval -n ${\\t} ==> \n" " /eval -n ${hide:-,${relay.network.password}} ==> --------\n" -" /eval -n ${cut:2,+,test} ==> te+\n" +" /eval -n ${cut:3,+,test} ==> tes+\n" +" /eval -n ${cut:+3,+,test} ==> te+\n" " /eval -n ${date:%H:%M:%S} ==> 07:46:40\n" " /eval -n ${if:${info:term_width}>80?big:small} ==> big\n" "\n" diff --git a/po/ja.po b/po/ja.po index e2b0409cf..4e7a1c7aa 100644 --- a/po/ja.po +++ b/po/ja.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2017-04-23 14:44+0200\n" +"POT-Creation-Date: 2017-04-24 22:34+0200\n" "PO-Revision-Date: 2017-04-23 09:00+0900\n" "Last-Translator: AYANOKOUZI, Ryuunosuke \n" "Language-Team: Japanese || [-n] -c " msgstr "[-n|-s] || [-n] -c " +#, fuzzy msgid "" " -n: display result without sending it to buffer (debug mode)\n" " -s: split expression before evaluating it (many commands can be " @@ -1515,9 +1516,10 @@ msgid "" " 1. an evaluated sub-string (format: \"eval:xxx\")\n" " 2. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" " 3. a string with chars to hide (format: \"hide:char,string\")\n" -" 4. a string with max chars (format: \"cut:max,suffix,string\")\n" -" or max chars displayed on screen (format: \"cutscr:max,suffix,string" -"\")\n" +" 4. a string with max chars (format: \"cut:max,suffix,string\" or \"cut:" +"+max,suffix,string\")\n" +" or max chars displayed on screen (format: \"cutscr:max,suffix,string\" " +"or \"cutscr:+max,suffix,string\")\n" " 5. a color (format: \"color:xxx\", see \"Plugin API reference\", function " "\"color\")\n" " 6. an info (format: \"info:name,arguments\", arguments are optional)\n" @@ -1555,7 +1557,8 @@ msgid "" " /eval -n ${window.buffer.number} ==> 1\n" " /eval -n ${\\t} ==> \n" " /eval -n ${hide:-,${relay.network.password}} ==> --------\n" -" /eval -n ${cut:2,+,test} ==> te+\n" +" /eval -n ${cut:3,+,test} ==> tes+\n" +" /eval -n ${cut:+3,+,test} ==> te+\n" " /eval -n ${date:%H:%M:%S} ==> 07:46:40\n" " /eval -n ${if:${info:term_width}>80?big:small} ==> big\n" "\n" diff --git a/po/pl.po b/po/pl.po index bde11cb19..5cf965a49 100644 --- a/po/pl.po +++ b/po/pl.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2017-04-23 14:44+0200\n" +"POT-Creation-Date: 2017-04-24 22:34+0200\n" "PO-Revision-Date: 2017-04-08 14:49+0200\n" "Last-Translator: Krzysztof Korościk \n" "Language-Team: weechat-dev \n" @@ -1550,9 +1550,10 @@ msgid "" " 1. an evaluated sub-string (format: \"eval:xxx\")\n" " 2. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" " 3. a string with chars to hide (format: \"hide:char,string\")\n" -" 4. a string with max chars (format: \"cut:max,suffix,string\")\n" -" or max chars displayed on screen (format: \"cutscr:max,suffix,string" -"\")\n" +" 4. a string with max chars (format: \"cut:max,suffix,string\" or \"cut:" +"+max,suffix,string\")\n" +" or max chars displayed on screen (format: \"cutscr:max,suffix,string\" " +"or \"cutscr:+max,suffix,string\")\n" " 5. a color (format: \"color:xxx\", see \"Plugin API reference\", function " "\"color\")\n" " 6. an info (format: \"info:name,arguments\", arguments are optional)\n" @@ -1590,7 +1591,8 @@ msgid "" " /eval -n ${window.buffer.number} ==> 1\n" " /eval -n ${\\t} ==> \n" " /eval -n ${hide:-,${relay.network.password}} ==> --------\n" -" /eval -n ${cut:2,+,test} ==> te+\n" +" /eval -n ${cut:3,+,test} ==> tes+\n" +" /eval -n ${cut:+3,+,test} ==> te+\n" " /eval -n ${date:%H:%M:%S} ==> 07:46:40\n" " /eval -n ${if:${info:term_width}>80?big:small} ==> big\n" "\n" diff --git a/po/pt.po b/po/pt.po index de052e89b..079285dfd 100644 --- a/po/pt.po +++ b/po/pt.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2017-04-23 14:44+0200\n" +"POT-Creation-Date: 2017-04-24 22:34+0200\n" "PO-Revision-Date: 2017-04-08 14:50+0200\n" "Last-Translator: Vasco Almeida \n" "Language-Team: Portuguese <>\n" @@ -1539,9 +1539,10 @@ msgid "" " 1. an evaluated sub-string (format: \"eval:xxx\")\n" " 2. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" " 3. a string with chars to hide (format: \"hide:char,string\")\n" -" 4. a string with max chars (format: \"cut:max,suffix,string\")\n" -" or max chars displayed on screen (format: \"cutscr:max,suffix,string" -"\")\n" +" 4. a string with max chars (format: \"cut:max,suffix,string\" or \"cut:" +"+max,suffix,string\")\n" +" or max chars displayed on screen (format: \"cutscr:max,suffix,string\" " +"or \"cutscr:+max,suffix,string\")\n" " 5. a color (format: \"color:xxx\", see \"Plugin API reference\", function " "\"color\")\n" " 6. an info (format: \"info:name,arguments\", arguments are optional)\n" @@ -1579,7 +1580,8 @@ msgid "" " /eval -n ${window.buffer.number} ==> 1\n" " /eval -n ${\\t} ==> \n" " /eval -n ${hide:-,${relay.network.password}} ==> --------\n" -" /eval -n ${cut:2,+,test} ==> te+\n" +" /eval -n ${cut:3,+,test} ==> tes+\n" +" /eval -n ${cut:+3,+,test} ==> te+\n" " /eval -n ${date:%H:%M:%S} ==> 07:46:40\n" " /eval -n ${if:${info:term_width}>80?big:small} ==> big\n" "\n" diff --git a/po/pt_BR.po b/po/pt_BR.po index d55a571a1..a537b7339 100644 --- a/po/pt_BR.po +++ b/po/pt_BR.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2017-04-23 14:44+0200\n" +"POT-Creation-Date: 2017-04-24 22:34+0200\n" "PO-Revision-Date: 2016-09-03 08:24+0200\n" "Last-Translator: Eduardo Elias \n" "Language-Team: weechat-dev \n" @@ -1548,9 +1548,10 @@ msgid "" " 1. an evaluated sub-string (format: \"eval:xxx\")\n" " 2. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" " 3. a string with chars to hide (format: \"hide:char,string\")\n" -" 4. a string with max chars (format: \"cut:max,suffix,string\")\n" -" or max chars displayed on screen (format: \"cutscr:max,suffix,string" -"\")\n" +" 4. a string with max chars (format: \"cut:max,suffix,string\" or \"cut:" +"+max,suffix,string\")\n" +" or max chars displayed on screen (format: \"cutscr:max,suffix,string\" " +"or \"cutscr:+max,suffix,string\")\n" " 5. a color (format: \"color:xxx\", see \"Plugin API reference\", function " "\"color\")\n" " 6. an info (format: \"info:name,arguments\", arguments are optional)\n" @@ -1588,7 +1589,8 @@ msgid "" " /eval -n ${window.buffer.number} ==> 1\n" " /eval -n ${\\t} ==> \n" " /eval -n ${hide:-,${relay.network.password}} ==> --------\n" -" /eval -n ${cut:2,+,test} ==> te+\n" +" /eval -n ${cut:3,+,test} ==> tes+\n" +" /eval -n ${cut:+3,+,test} ==> te+\n" " /eval -n ${date:%H:%M:%S} ==> 07:46:40\n" " /eval -n ${if:${info:term_width}>80?big:small} ==> big\n" "\n" diff --git a/po/ru.po b/po/ru.po index 5e1c61ff0..2835866c3 100644 --- a/po/ru.po +++ b/po/ru.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2017-04-23 14:44+0200\n" +"POT-Creation-Date: 2017-04-24 22:34+0200\n" "PO-Revision-Date: 2017-01-06 22:06+0100\n" "Last-Translator: Aleksey V Zapparov AKA ixti \n" "Language-Team: weechat-dev \n" @@ -1415,9 +1415,10 @@ msgid "" " 1. an evaluated sub-string (format: \"eval:xxx\")\n" " 2. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" " 3. a string with chars to hide (format: \"hide:char,string\")\n" -" 4. a string with max chars (format: \"cut:max,suffix,string\")\n" -" or max chars displayed on screen (format: \"cutscr:max,suffix,string" -"\")\n" +" 4. a string with max chars (format: \"cut:max,suffix,string\" or \"cut:" +"+max,suffix,string\")\n" +" or max chars displayed on screen (format: \"cutscr:max,suffix,string\" " +"or \"cutscr:+max,suffix,string\")\n" " 5. a color (format: \"color:xxx\", see \"Plugin API reference\", function " "\"color\")\n" " 6. an info (format: \"info:name,arguments\", arguments are optional)\n" @@ -1455,7 +1456,8 @@ msgid "" " /eval -n ${window.buffer.number} ==> 1\n" " /eval -n ${\\t} ==> \n" " /eval -n ${hide:-,${relay.network.password}} ==> --------\n" -" /eval -n ${cut:2,+,test} ==> te+\n" +" /eval -n ${cut:3,+,test} ==> tes+\n" +" /eval -n ${cut:+3,+,test} ==> te+\n" " /eval -n ${date:%H:%M:%S} ==> 07:46:40\n" " /eval -n ${if:${info:term_width}>80?big:small} ==> big\n" "\n" diff --git a/po/tr.po b/po/tr.po index 1d0bca15e..4f15ef30f 100644 --- a/po/tr.po +++ b/po/tr.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2017-04-23 14:44+0200\n" +"POT-Creation-Date: 2017-04-24 22:34+0200\n" "PO-Revision-Date: 2017-01-06 22:07+0100\n" "Last-Translator: Hasan Kiran \n" "Language-Team: weechat-dev \n" @@ -1249,9 +1249,10 @@ msgid "" " 1. an evaluated sub-string (format: \"eval:xxx\")\n" " 2. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" " 3. a string with chars to hide (format: \"hide:char,string\")\n" -" 4. a string with max chars (format: \"cut:max,suffix,string\")\n" -" or max chars displayed on screen (format: \"cutscr:max,suffix,string" -"\")\n" +" 4. a string with max chars (format: \"cut:max,suffix,string\" or \"cut:" +"+max,suffix,string\")\n" +" or max chars displayed on screen (format: \"cutscr:max,suffix,string\" " +"or \"cutscr:+max,suffix,string\")\n" " 5. a color (format: \"color:xxx\", see \"Plugin API reference\", function " "\"color\")\n" " 6. an info (format: \"info:name,arguments\", arguments are optional)\n" @@ -1289,7 +1290,8 @@ msgid "" " /eval -n ${window.buffer.number} ==> 1\n" " /eval -n ${\\t} ==> \n" " /eval -n ${hide:-,${relay.network.password}} ==> --------\n" -" /eval -n ${cut:2,+,test} ==> te+\n" +" /eval -n ${cut:3,+,test} ==> tes+\n" +" /eval -n ${cut:+3,+,test} ==> te+\n" " /eval -n ${date:%H:%M:%S} ==> 07:46:40\n" " /eval -n ${if:${info:term_width}>80?big:small} ==> big\n" "\n" diff --git a/po/weechat.pot b/po/weechat.pot index dadce4ee9..9a99de944 100644 --- a/po/weechat.pot +++ b/po/weechat.pot @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2017-04-23 14:44+0200\n" +"POT-Creation-Date: 2017-04-24 22:34+0200\n" "PO-Revision-Date: 2014-08-16 10:27+0200\n" "Last-Translator: Sébastien Helleu \n" "Language-Team: weechat-dev \n" @@ -1252,9 +1252,10 @@ msgid "" " 1. an evaluated sub-string (format: \"eval:xxx\")\n" " 2. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" " 3. a string with chars to hide (format: \"hide:char,string\")\n" -" 4. a string with max chars (format: \"cut:max,suffix,string\")\n" -" or max chars displayed on screen (format: \"cutscr:max,suffix,string" -"\")\n" +" 4. a string with max chars (format: \"cut:max,suffix,string\" or \"cut:" +"+max,suffix,string\")\n" +" or max chars displayed on screen (format: \"cutscr:max,suffix,string\" " +"or \"cutscr:+max,suffix,string\")\n" " 5. a color (format: \"color:xxx\", see \"Plugin API reference\", function " "\"color\")\n" " 6. an info (format: \"info:name,arguments\", arguments are optional)\n" @@ -1292,7 +1293,8 @@ msgid "" " /eval -n ${window.buffer.number} ==> 1\n" " /eval -n ${\\t} ==> \n" " /eval -n ${hide:-,${relay.network.password}} ==> --------\n" -" /eval -n ${cut:2,+,test} ==> te+\n" +" /eval -n ${cut:3,+,test} ==> tes+\n" +" /eval -n ${cut:+3,+,test} ==> te+\n" " /eval -n ${date:%H:%M:%S} ==> 07:46:40\n" " /eval -n ${if:${info:term_width}>80?big:small} ==> big\n" "\n" diff --git a/src/core/wee-command.c b/src/core/wee-command.c index 5eab9522e..365c795c4 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -7269,9 +7269,11 @@ command_init () " 1. an evaluated sub-string (format: \"eval:xxx\")\n" " 2. a string with escaped chars (format: \"esc:xxx\" or \"\\xxx\")\n" " 3. a string with chars to hide (format: \"hide:char,string\")\n" - " 4. a string with max chars (format: \"cut:max,suffix,string\")\n" + " 4. a string with max chars (format: \"cut:max,suffix,string\" " + "or \"cut:+max,suffix,string\")\n" " or max chars displayed on screen " - "(format: \"cutscr:max,suffix,string\")\n" + "(format: \"cutscr:max,suffix,string\" or " + "\"cutscr:+max,suffix,string\")\n" " 5. a color (format: \"color:xxx\", see \"Plugin API " "reference\", function \"color\")\n" " 6. an info (format: \"info:name,arguments\", arguments are " @@ -7311,7 +7313,8 @@ command_init () " /eval -n ${window.buffer.number} ==> 1\n" " /eval -n ${\\t} ==> \n" " /eval -n ${hide:-,${relay.network.password}} ==> --------\n" - " /eval -n ${cut:2,+,test} ==> te+\n" + " /eval -n ${cut:3,+,test} ==> tes+\n" + " /eval -n ${cut:+3,+,test} ==> te+\n" " /eval -n ${date:%H:%M:%S} ==> 07:46:40\n" " /eval -n ${if:${info:term_width}>80?big:small} ==> big\n" "\n" diff --git a/src/core/wee-eval.c b/src/core/wee-eval.c index 016d99c2d..4e5af5e95 100644 --- a/src/core/wee-eval.c +++ b/src/core/wee-eval.c @@ -326,6 +326,7 @@ eval_replace_vars_cb (void *data, const char *text) struct t_hdata *hdata; void *pointer; int i, length_hide_char, length, index, rc, extra_vars_eval, screen; + int count_suffix; long number; long unsigned int ptr; time_t date; @@ -436,6 +437,12 @@ eval_replace_vars_cb (void *data, const char *text) pos = strchr (text + length, ','); if (!pos) return strdup (""); + count_suffix = 0; + if (text[length] == '+') + { + length++; + count_suffix = 1; + } pos2 = strchr (pos + 1, ','); if (!pos2) return strdup (""); @@ -452,7 +459,7 @@ eval_replace_vars_cb (void *data, const char *text) tmp = strndup (pos + 1, pos2 - pos - 1); if (!tmp) return strdup (""); - value = string_cut (pos2 + 1, number, screen, tmp); + value = string_cut (pos2 + 1, number, count_suffix, screen, tmp); free (tmp); return value; } diff --git a/src/core/wee-string.c b/src/core/wee-string.c index 2593ed279..f974ac063 100644 --- a/src/core/wee-string.c +++ b/src/core/wee-string.c @@ -96,13 +96,16 @@ string_strndup (const char *string, int length) * Cuts a string after max "length" chars, adds an optional suffix * after the string if it is cut. * + * If count_suffix == 1, the length of suffix is counted in the max length. + * * If screen == 1, the cut is based on width of chars displayed. * * Note: result must be freed after use. */ char * -string_cut (const char *string, int length, int screen, const char *cut_suffix) +string_cut (const char *string, int length, int count_suffix, int screen, + const char *cut_suffix) { int length_result, length_cut_suffix; char *result; @@ -113,7 +116,7 @@ string_cut (const char *string, int length, int screen, const char *cut_suffix) else ptr_string = gui_chat_string_add_offset (string, length); - if (!ptr_string[0]) + if (!ptr_string || !ptr_string[0]) { /* no cut */ return strdup (string); @@ -122,6 +125,24 @@ string_cut (const char *string, int length, int screen, const char *cut_suffix) if (cut_suffix && cut_suffix[0]) { length_cut_suffix = strlen (cut_suffix); + if (count_suffix) + { + if (screen) + length -= utf8_strlen_screen (cut_suffix); + else + length -= length_cut_suffix; + if (length < 0) + return strdup (""); + if (screen) + ptr_string = gui_chat_string_add_offset_screen (string, length); + else + ptr_string = gui_chat_string_add_offset (string, length); + if (!ptr_string || !ptr_string[0]) + { + /* no cut */ + return strdup (string); + } + } length_result = (ptr_string - string) + length_cut_suffix + 1; result = malloc (length_result); if (!result) diff --git a/src/core/wee-string.h b/src/core/wee-string.h index 3769cf299..0c2f0d997 100644 --- a/src/core/wee-string.h +++ b/src/core/wee-string.h @@ -36,8 +36,8 @@ struct t_string_dyn struct t_hashtable; extern char *string_strndup (const char *string, int length); -extern char *string_cut (const char *string, int length, int screen, - const char *cut_suffix); +extern char *string_cut (const char *string, int length, int count_suffix, + int screen, const char *cut_suffix); extern void string_tolower (char *string); extern void string_toupper (char *string); extern int string_strcasecmp (const char *string1, const char *string2); diff --git a/tests/unit/core/test-eval.cpp b/tests/unit/core/test-eval.cpp index e0bd236b7..14f60f80b 100644 --- a/tests/unit/core/test-eval.cpp +++ b/tests/unit/core/test-eval.cpp @@ -237,6 +237,42 @@ TEST(Eval, EvalExpression) WEE_CHECK_EVAL("te+", "${cut:2,+,test}"); WEE_CHECK_EVAL("te+", "${cutscr:2,+,test}"); + WEE_CHECK_EVAL("tes", "${cut:3,,test}"); + WEE_CHECK_EVAL("tes", "${cutscr:3,,test}"); + WEE_CHECK_EVAL("tes", "${cut:+3,,test}"); + WEE_CHECK_EVAL("tes", "${cutscr:+3,,test}"); + + WEE_CHECK_EVAL("tes+", "${cut:3,+,test}"); + WEE_CHECK_EVAL("tes+", "${cutscr:3,+,test}"); + WEE_CHECK_EVAL("tes++", "${cut:3,++,test}"); + WEE_CHECK_EVAL("tes++", "${cutscr:3,++,test}"); + WEE_CHECK_EVAL("tes+++", "${cut:3,+++,test}"); + WEE_CHECK_EVAL("tes+++", "${cutscr:3,+++,test}"); + WEE_CHECK_EVAL("tes++++", "${cut:3,++++,test}"); + WEE_CHECK_EVAL("tes++++", "${cutscr:3,++++,test}"); + WEE_CHECK_EVAL("tes…", "${cut:3,…,test}"); + WEE_CHECK_EVAL("tes…", "${cutscr:3,…,test}"); + WEE_CHECK_EVAL("te+", "${cut:+3,+,test}"); + WEE_CHECK_EVAL("te+", "${cutscr:+3,+,test}"); + WEE_CHECK_EVAL("…", "${cut:+3,…,test}"); + WEE_CHECK_EVAL("te…", "${cutscr:+3,…,test}"); + WEE_CHECK_EVAL("t++", "${cut:+3,++,test}"); + WEE_CHECK_EVAL("t++", "${cutscr:+3,++,test}"); + WEE_CHECK_EVAL("+++", "${cut:+3,+++,test}"); + WEE_CHECK_EVAL("+++", "${cutscr:+3,+++,test}"); + WEE_CHECK_EVAL("", "${cut:+3,++++,test}"); + WEE_CHECK_EVAL("", "${cutscr:+3,++++,test}"); + + WEE_CHECK_EVAL("test", "${cut:4,,test}"); + WEE_CHECK_EVAL("test", "${cutscr:4,,test}"); + WEE_CHECK_EVAL("test", "${cut:+4,,test}"); + WEE_CHECK_EVAL("test", "${cutscr:+4,,test}"); + + WEE_CHECK_EVAL("test", "${cut:4,+,test}"); + WEE_CHECK_EVAL("test", "${cutscr:4,+,test}"); + WEE_CHECK_EVAL("test", "${cut:+4,+,test}"); + WEE_CHECK_EVAL("test", "${cutscr:+4,+,test}"); + WEE_CHECK_EVAL("éà", "${cut:2,,éàô}"); WEE_CHECK_EVAL("éà", "${cutscr:2,,éàô}");