Index: openacs-4/packages/acs-admin/www/auth/authority.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-admin/www/auth/authority.tcl,v diff -u -N -r1.28.2.1 -r1.28.2.2 --- openacs-4/packages/acs-admin/www/auth/authority.tcl 12 Mar 2019 17:35:03 -0000 1.28.2.1 +++ openacs-4/packages/acs-admin/www/auth/authority.tcl 16 Dec 2019 17:55:12 -0000 1.28.2.2 @@ -298,7 +298,7 @@ set end_time_pretty [lc_time_fmt $end_time_ansi "%x %X"] set interactive_pretty [expr {$interactive_p eq "t" ? $yes : $no}] - set short_message [string_truncate -len 30 -- $message] + set short_message [ad_string_truncate -len 30 -- $message] set actions_per_minute {} if { $run_time_seconds > 0 && $num_actions > 0 } { Index: openacs-4/packages/acs-admin/www/auth/batch-job.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-admin/www/auth/batch-job.tcl,v diff -u -N -r1.17.2.1 -r1.17.2.2 --- openacs-4/packages/acs-admin/www/auth/batch-job.tcl 12 Mar 2019 17:30:52 -0000 1.17.2.1 +++ openacs-4/packages/acs-admin/www/auth/batch-job.tcl 16 Dec 2019 17:55:12 -0000 1.17.2.2 @@ -165,7 +165,7 @@ } else { set short_message "" } - set short_message [string_truncate -len 75 -- $short_message] + set short_message [ad_string_truncate -len 75 -- $short_message] if { $user_exists_p && $user_id ne "" } { set user_url [acs_community_member_admin_url -user_id $user_id] Index: openacs-4/packages/acs-lang/www/admin/message-conflicts.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-lang/www/admin/message-conflicts.tcl,v diff -u -N -r1.7 -r1.7.2.1 --- openacs-4/packages/acs-lang/www/admin/message-conflicts.tcl 7 Aug 2017 23:47:57 -0000 1.7 +++ openacs-4/packages/acs-lang/www/admin/message-conflicts.tcl 16 Dec 2019 17:55:12 -0000 1.7.2.1 @@ -121,8 +121,8 @@ set accept_url [export_vars -base "message-conflict-resolve" { package_key locale message_key {return_url [ad_return_url]}}] set revert_url [export_vars -base "message-conflict-revert" { package_key locale message_key {return_url [ad_return_url]}}] - set message_truncated [string_truncate -len 150 -- $message] - set old_message_truncated [string_truncate -len 150 -- $old_message] + set message_truncated [ad_string_truncate -len 150 -- $message] + set old_message_truncated [ad_string_truncate -len 150 -- $old_message] } # Local variables: Index: openacs-4/packages/acs-tcl/tcl/text-html-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/text-html-procs.tcl,v diff -u -N -r1.109.2.11 -r1.109.2.12 --- openacs-4/packages/acs-tcl/tcl/text-html-procs.tcl 16 Dec 2019 17:22:50 -0000 1.109.2.11 +++ openacs-4/packages/acs-tcl/tcl/text-html-procs.tcl 16 Dec 2019 17:55:12 -0000 1.109.2.12 @@ -2341,7 +2341,7 @@ set text [util_close_html_tags $text $truncate_len $truncate_len $ellipsis $more] } text/plain { - set text [string_truncate -ellipsis $ellipsis -more $more -len $truncate_len -- $text] + set text [ad_string_truncate -ellipsis $ellipsis -more $more -len $truncate_len -- $text] } } @@ -2447,7 +2447,40 @@ # ##### -ad_proc -public string_truncate { +ad_proc -deprecated ad_string_truncate args { + Truncates a string to len characters adding the string provided in + the ellipsis parameter if the string was truncated. + + The length of the resulting string, including the ellipsis, is + guaranteed to be shorter or equal than the len specified. + + Should always be called as ad_string_truncate [-flags ...] -- string + since otherwise strings which start with a - will treated as + switches, and will cause an error. + + @param len The length to truncate to. If zero, no truncation will occur. + + @param ellipsis This will get put at the end of the truncated string, if the string was truncated. + However, this counts towards the total string length, so that the returned string + including ellipsis is guaranteed to be shorter or equal than the 'len' provided. + + @param more This will get put at the end of the truncated string, if the string was truncated. + + @param string The string to truncate. + + @return The truncated string + + @author Lars Pind (lars@pinds.com) + @creation-date September 8, 2002 + + DEPRECATED: does not comply with OpenACS naming convention + + @see ad_string_truncate +} { + return [ad_string_truncate {*}$args] +} + +ad_proc -public ad_string_truncate { {-len 200} {-ellipsis "..."} {-more ""} @@ -2460,7 +2493,7 @@ The length of the resulting string, including the ellipsis, is guaranteed to be shorter or equal than the len specified. - Should always be called as string_truncate [-flags ...] -- string + Should always be called as ad_string_truncate [-flags ...] -- string since otherwise strings which start with a - will treated as switches, and will cause an error. @@ -2499,6 +2532,41 @@ return $string } +ad_proc -deprecated ad_string_truncate_middle args { + Cut middle part of a string in case it is too long + + DEPRECATED: does not comply with OpenACS naming convention + + @see ad_string_truncate_middle +} { + return [ad_string_truncate_middle {*}$args] +} + +ad_proc ad_string_truncate_middle { + {-ellipsis ...} + {-len 100} + string +} { + Cut middle part of a string in case it is too long. + + @param ellipsis placeholder for the portion of text being left out + @param len length after which we are starting cutting text + @param string + + @see ad_string_truncate + + @return truncated string +} { + set string [string trim $string] + if {[string length $string]>$len} { + set half [expr {($len-2)/2}] + set left [string trimright [string range $string 0 $half]] + set right [string trimleft [string range $string end-$half end]] + return $left$ellipsis$right + } + return $string +} + ad_proc -public ad_pad { -left:boolean -right:boolean Index: openacs-4/packages/acs-tcl/tcl/test/html-conversion-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/test/html-conversion-procs.tcl,v diff -u -N -r1.20.2.4 -r1.20.2.5 --- openacs-4/packages/acs-tcl/tcl/test/html-conversion-procs.tcl 29 Sep 2019 14:54:56 -0000 1.20.2.4 +++ openacs-4/packages/acs-tcl/tcl/test/html-conversion-procs.tcl 16 Dec 2019 17:55:12 -0000 1.20.2.5 @@ -219,38 +219,38 @@ aa_register_case \ -cats {api smoke} \ - -procs {string_truncate} \ - string_truncate { + -procs {ad_string_truncate} \ + ad_string_truncate { Testing string truncation } { - aa_equals "" [string_truncate -len 5 -ellipsis "" -- "foo"] "foo" - aa_equals "" [string_truncate -len 5 -ellipsis "" -- "foobar greble"] "fooba" - aa_equals "" [string_truncate -len 6 -ellipsis "" -- "foobar greble"] "foobar" - aa_equals "" [string_truncate -len 7 -ellipsis "" -- "foobar greble"] "foobar" - aa_equals "" [string_truncate -len 7 -ellipsis "" -- "foobar\tgreble"] "foobar" - aa_equals "" [string_truncate -len 7 -ellipsis "" -- "foobar\ngreble"] "foobar" - aa_equals "" [string_truncate -len 7 -ellipsis "" -- "foobar\rgreble"] "foobar" - aa_equals "" [string_truncate -len 7 -ellipsis "" -- "foobar\fgreble"] "foobar" - aa_equals "" [string_truncate -len 8 -ellipsis "" -- "foobar greble"] "foobar" - aa_equals "" [string_truncate -len 9 -ellipsis "" -- "foobar greble"] "foobar" - aa_equals "" [string_truncate -len 10 -ellipsis "" -- "foobar greble"] "foobar" - aa_equals "" [string_truncate -len 11 -ellipsis "" -- "foobar greble"] "foobar" - aa_equals "" [string_truncate -len 12 -ellipsis "" -- "foobar greble"] "foobar" - aa_equals "" [string_truncate -len 13 -ellipsis "" -- "foobar greble"] "foobar greble" + aa_equals "" [ad_string_truncate -len 5 -ellipsis "" -- "foo"] "foo" + aa_equals "" [ad_string_truncate -len 5 -ellipsis "" -- "foobar greble"] "fooba" + aa_equals "" [ad_string_truncate -len 6 -ellipsis "" -- "foobar greble"] "foobar" + aa_equals "" [ad_string_truncate -len 7 -ellipsis "" -- "foobar greble"] "foobar" + aa_equals "" [ad_string_truncate -len 7 -ellipsis "" -- "foobar\tgreble"] "foobar" + aa_equals "" [ad_string_truncate -len 7 -ellipsis "" -- "foobar\ngreble"] "foobar" + aa_equals "" [ad_string_truncate -len 7 -ellipsis "" -- "foobar\rgreble"] "foobar" + aa_equals "" [ad_string_truncate -len 7 -ellipsis "" -- "foobar\fgreble"] "foobar" + aa_equals "" [ad_string_truncate -len 8 -ellipsis "" -- "foobar greble"] "foobar" + aa_equals "" [ad_string_truncate -len 9 -ellipsis "" -- "foobar greble"] "foobar" + aa_equals "" [ad_string_truncate -len 10 -ellipsis "" -- "foobar greble"] "foobar" + aa_equals "" [ad_string_truncate -len 11 -ellipsis "" -- "foobar greble"] "foobar" + aa_equals "" [ad_string_truncate -len 12 -ellipsis "" -- "foobar greble"] "foobar" + aa_equals "" [ad_string_truncate -len 13 -ellipsis "" -- "foobar greble"] "foobar greble" - aa_equals "" [string_truncate -len 5 -ellipsis "..." -- "foo"] "foo" - aa_equals "" [string_truncate -len 5 -ellipsis "..." -- "foobar greble"] "fo..." - aa_equals "" [string_truncate -len 6 -ellipsis "..." -- "foobar greble"] "foo..." - aa_equals "" [string_truncate -len 7 -ellipsis "..." -- "foobar greble"] "foob..." - aa_equals "" [string_truncate -len 8 -ellipsis "..." -- "foobar greble"] "fooba..." - aa_equals "" [string_truncate -len 9 -ellipsis "..." -- "foobar greble"] "foobar..." - aa_equals "" [string_truncate -len 10 -ellipsis "..." -- "foobar greble"] "foobar..." - aa_equals "" [string_truncate -len 11 -ellipsis "..." -- "foobar greble"] "foobar..." - aa_equals "" [string_truncate -len 12 -ellipsis "..." -- "foobar greble"] "foobar..." - aa_equals "" [string_truncate -len 13 -ellipsis "..." -- "foobar greble"] "foobar greble" + aa_equals "" [ad_string_truncate -len 5 -ellipsis "..." -- "foo"] "foo" + aa_equals "" [ad_string_truncate -len 5 -ellipsis "..." -- "foobar greble"] "fo..." + aa_equals "" [ad_string_truncate -len 6 -ellipsis "..." -- "foobar greble"] "foo..." + aa_equals "" [ad_string_truncate -len 7 -ellipsis "..." -- "foobar greble"] "foob..." + aa_equals "" [ad_string_truncate -len 8 -ellipsis "..." -- "foobar greble"] "fooba..." + aa_equals "" [ad_string_truncate -len 9 -ellipsis "..." -- "foobar greble"] "foobar..." + aa_equals "" [ad_string_truncate -len 10 -ellipsis "..." -- "foobar greble"] "foobar..." + aa_equals "" [ad_string_truncate -len 11 -ellipsis "..." -- "foobar greble"] "foobar..." + aa_equals "" [ad_string_truncate -len 12 -ellipsis "..." -- "foobar greble"] "foobar..." + aa_equals "" [ad_string_truncate -len 13 -ellipsis "..." -- "foobar greble"] "foobar greble" set long_string [string repeat "Very long text. " 100] - aa_equals "No truncation" [string_truncate -len [string length $long_string] -- $long_string] $long_string + aa_equals "No truncation" [ad_string_truncate -len [string length $long_string] -- $long_string] $long_string } Index: openacs-4/packages/acs-templating/tcl/list-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/list-procs.tcl,v diff -u -N -r1.94.2.6 -r1.94.2.7 --- openacs-4/packages/acs-templating/tcl/list-procs.tcl 26 Nov 2019 17:11:53 -0000 1.94.2.6 +++ openacs-4/packages/acs-templating/tcl/list-procs.tcl 16 Dec 2019 17:55:12 -0000 1.94.2.7 @@ -1841,7 +1841,7 @@ $filter_properties_name \ $filter_properties(label) \ $filter_properties(clear_url) \ - [string_truncate -len 25 -- $label] \ + [ad_string_truncate -len 25 -- $label] \ $value \ $url \ $label \ Index: openacs-4/packages/news-portlet/www/summary.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/news-portlet/www/summary.tcl,v diff -u -N -r1.10 -r1.10.2.1 --- openacs-4/packages/news-portlet/www/summary.tcl 7 Aug 2017 23:48:12 -0000 1.10 +++ openacs-4/packages/news-portlet/www/summary.tcl 16 Dec 2019 17:55:12 -0000 1.10.2.1 @@ -64,7 +64,7 @@ set more_link "" set summary_length [news_portlet::get_summary_length] if { [string length $publish_body] > $summary_length } { - set publish_body [string_truncate -len $summary_length -- $publish_body] + set publish_body [ad_string_truncate -len $summary_length -- $publish_body] set more_link "

» [_ news-portlet.Read_more]

" } Index: openacs-4/packages/notifications/tcl/notification-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/notifications/tcl/notification-procs.tcl,v diff -u -N -r1.23 -r1.23.2.1 --- openacs-4/packages/notifications/tcl/notification-procs.tcl 17 Aug 2018 13:02:43 -0000 1.23 +++ openacs-4/packages/notifications/tcl/notification-procs.tcl 16 Dec 2019 17:55:12 -0000 1.23.2.1 @@ -310,7 +310,7 @@ } # Truncate notif_subject to the max len of 100 - set notif_subject [string_truncate -len 100 -- $notif_subject] + set notif_subject [ad_string_truncate -len 100 -- $notif_subject] # Set up the vars set extra_vars [ns_set create] Index: openacs-4/packages/xotcl-request-monitor/tcl/throttle_mod-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xotcl-request-monitor/tcl/throttle_mod-procs.tcl,v diff -u -N -r1.67.2.7 -r1.67.2.8 --- openacs-4/packages/xotcl-request-monitor/tcl/throttle_mod-procs.tcl 9 Aug 2019 08:41:44 -0000 1.67.2.7 +++ openacs-4/packages/xotcl-request-monitor/tcl/throttle_mod-procs.tcl 16 Dec 2019 17:55:12 -0000 1.67.2.8 @@ -1698,19 +1698,6 @@ } } -ad_proc string_truncate_middle {{-ellipsis ...} {-len 100} string} { - cut middle part of a string in case it is too long -} { - set string [string trim $string] - if {[string length $string]>$len} { - set half [expr {($len-2)/2}] - set left [string trimright [string range $string 0 $half]] - set right [string trimleft [string range $string end-$half end]] - return $left$ellipsis$right - } - return $string -} - namespace eval ::xo { proc is_ip {key} { Index: openacs-4/packages/xotcl-request-monitor/tcl/test/throttle_mod-test-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xotcl-request-monitor/tcl/test/Attic/throttle_mod-test-procs.tcl,v diff -u -N -r1.1.2.2 -r1.1.2.3 --- openacs-4/packages/xotcl-request-monitor/tcl/test/throttle_mod-test-procs.tcl 3 Sep 2019 06:35:55 -0000 1.1.2.2 +++ openacs-4/packages/xotcl-request-monitor/tcl/test/throttle_mod-test-procs.tcl 16 Dec 2019 17:55:12 -0000 1.1.2.3 @@ -7,21 +7,21 @@ aa_register_case \ -cats {api smoke production_safe} \ - -procs {string_truncate_middle} \ - string_truncate_middle { + -procs {ad_string_truncate_middle} \ + ad_string_truncate_middle { - Test the string_truncate_middle proc + Test the ad_string_truncate_middle proc @author Hanifa Hasan } { set full_string "sadlfvnsaödcösalcmksadöldcmsasdcsadvwaef4q3t54zbrefsydfsd" - aa_equals "Empty ellipsis short length" [string_truncate_middle -ellipsis "" -len 5 $full_string ] "sasd" - aa_equals "Empty ellipsis" [string_truncate_middle -ellipsis "" $full_string ] "sadlfvnsaödcösalcmksadöldcmsasdcsadvwaef4q3t54zbrefsydfsd" - aa_equals "No length" [string_truncate_middle -ellipsis ":::::::::::" $full_string ] "sadlfvnsaödcösalcmksadöldcmsasdcsadvwaef4q3t54zbrefsydfsd" - aa_equals "Short length" [string_truncate_middle -ellipsis ":::::::::::" -len 10 $full_string ] "sadlf:::::::::::ydfsd" - aa_equals "Default options" [string_truncate_middle $full_string ] "sadlfvnsaödcösalcmksadöldcmsasdcsadvwaef4q3t54zbrefsydfsd" - aa_equals "Length 0, default ellipsis" [string_truncate_middle -len 0 $full_string ] "..." - aa_equals "Length 25, default ellipsis" [string_truncate_middle -len 25 $full_string ] "sadlfvnsaödc...4zbrefsydfsd" + aa_equals "Empty ellipsis short length" [ad_string_truncate_middle -ellipsis "" -len 5 $full_string ] "sasd" + aa_equals "Empty ellipsis" [ad_string_truncate_middle -ellipsis "" $full_string ] "sadlfvnsaödcösalcmksadöldcmsasdcsadvwaef4q3t54zbrefsydfsd" + aa_equals "No length" [ad_string_truncate_middle -ellipsis ":::::::::::" $full_string ] "sadlfvnsaödcösalcmksadöldcmsasdcsadvwaef4q3t54zbrefsydfsd" + aa_equals "Short length" [ad_string_truncate_middle -ellipsis ":::::::::::" -len 10 $full_string ] "sadlf:::::::::::ydfsd" + aa_equals "Default options" [ad_string_truncate_middle $full_string ] "sadlfvnsaödcösalcmksadöldcmsasdcsadvwaef4q3t54zbrefsydfsd" + aa_equals "Length 0, default ellipsis" [ad_string_truncate_middle -len 0 $full_string ] "..." + aa_equals "Length 25, default ellipsis" [ad_string_truncate_middle -len 25 $full_string ] "sadlfvnsaödc...4zbrefsydfsd" } # Local variables: Index: openacs-4/packages/xotcl-request-monitor/www/last-requests.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xotcl-request-monitor/www/last-requests.tcl,v diff -u -N -r1.11 -r1.11.2.1 --- openacs-4/packages/xotcl-request-monitor/www/last-requests.tcl 5 Jul 2018 15:14:01 -0000 1.11 +++ openacs-4/packages/xotcl-request-monitor/www/last-requests.tcl 16 Dec 2019 17:55:12 -0000 1.11.2.1 @@ -73,7 +73,7 @@ if {$exclude} continue } set diff [expr {$last_timestamp-$timestamp}] - set url_label [string_truncate_middle -len 70 $url] + set url_label [ad_string_truncate_middle -len 70 $url] t1 add -time [clock format $timestamp] \ -timediff $diff \ -url $url_label \ Index: openacs-4/packages/xotcl-request-monitor/www/stat-details.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xotcl-request-monitor/www/stat-details.tcl,v diff -u -N -r1.13.2.1 -r1.13.2.2 --- openacs-4/packages/xotcl-request-monitor/www/stat-details.tcl 30 Mar 2019 19:46:54 -0000 1.13.2.1 +++ openacs-4/packages/xotcl-request-monitor/www/stat-details.tcl 16 Dec 2019 17:55:12 -0000 1.13.2.2 @@ -188,7 +188,7 @@ if {$exclude} continue } - t1 add -url [string_truncate_middle -len 80 $url] \ + t1 add -url [ad_string_truncate_middle -len 80 $url] \ -url.href [expr {[string match "*...*" $url] ? "" : "[ad_url]$url" }] \ -totaltime [lindex $l 1] \ -cnt [lindex $l 2] \