aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2014-11-16 14:23:54 +1000
committerSteve Bennett <steveb@workware.net.au>2014-11-17 12:22:48 +1000
commit77329fbe453beddd11607fa437ae83940435e1a4 (patch)
tree87f660f38efa57c94fe1f0fa8d714c2288e266da
parente60018c2797b6edb2d05336178c88e429ba62f73 (diff)
downloadjimtcl-77329fbe453beddd11607fa437ae83940435e1a4.zip
jimtcl-77329fbe453beddd11607fa437ae83940435e1a4.tar.gz
jimtcl-77329fbe453beddd11607fa437ae83940435e1a4.tar.bz2
Implement string cat (TIP #429)
Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r--Tcl_shipped.html34
-rw-r--r--jim.c23
-rw-r--r--jim_tcl.txt3
-rw-r--r--nshelper.tcl2
-rw-r--r--tests/string.test21
5 files changed, 68 insertions, 15 deletions
diff --git a/Tcl_shipped.html b/Tcl_shipped.html
index 20781b8..cc1e46e 100644
--- a/Tcl_shipped.html
+++ b/Tcl_shipped.html
@@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
-<meta name="generator" content="AsciiDoc 8.6.6" />
+<meta name="generator" content="AsciiDoc 8.6.9" />
<title>Jim Tcl(n)</title>
<style type="text/css">
/* Shared CSS for AsciiDoc xhtml11 and html5 backends */
@@ -581,7 +581,7 @@ toc: function (toclevels) {
function tocEntries(el, toclevels) {
var result = new Array;
- var re = new RegExp('[hH]([2-'+(toclevels+1)+'])');
+ var re = new RegExp('[hH]([1-'+(toclevels+1)+'])');
// Function that scans the DOM tree for header elements (the DOM2
// nodeIterator API would be a better technique but not supported by all
// browsers).
@@ -610,7 +610,7 @@ toc: function (toclevels) {
var i;
for (i = 0; i < toc.childNodes.length; i++) {
var entry = toc.childNodes[i];
- if (entry.nodeName == 'div'
+ if (entry.nodeName.toLowerCase() == 'div'
&& entry.getAttribute("class")
&& entry.getAttribute("class").match(/^toclevel/))
tocEntriesToRemove.push(entry);
@@ -656,7 +656,7 @@ footnotes: function () {
var entriesToRemove = [];
for (i = 0; i < noteholder.childNodes.length; i++) {
var entry = noteholder.childNodes[i];
- if (entry.nodeName == 'div' && entry.getAttribute("class") == "footnote")
+ if (entry.nodeName.toLowerCase() == 'div' && entry.getAttribute("class") == "footnote")
entriesToRemove.push(entry);
}
for (i = 0; i < entriesToRemove.length; i++) {
@@ -4869,15 +4869,19 @@ affect the loop count.</p></div>
</div>
<div class="sect2">
<h3 id="_lindex">lindex</h3>
-<div class="paragraph"><p><tt><strong>lindex</strong> <em>list index</em></tt></p></div>
+<div class="paragraph"><p><tt><strong>lindex</strong> <em>list ?index &#8230;?</em></tt></p></div>
<div class="paragraph"><p>Treats <tt><em>list</em></tt> as a Tcl list and returns element <tt><em>index</em></tt> from it
(0 refers to the first element of the list).
See STRING AND LIST INDEX SPECIFICATIONS for all allowed forms for <tt><em>index</em></tt>.</p></div>
<div class="paragraph"><p>In extracting the element, <tt><em>lindex</em></tt> observes the same rules concerning
braces and quotes and backslashes as the Tcl command interpreter; however,
variable substitution and command substitution do not occur.</p></div>
+<div class="paragraph"><p>If no index values are given, simply returns <tt><em>list</em></tt></p></div>
<div class="paragraph"><p>If <tt><em>index</em></tt> is negative or greater than or equal to the number of elements
-in <tt><em>value</em></tt>, then an empty string is returned.</p></div>
+in <tt><em>list</em></tt>, then an empty string is returned.</p></div>
+<div class="paragraph"><p>If additional index arguments are supplied, then each argument is
+used in turn to select an element from the previous indexing
+operation, allowing the script to select elements from sublists.</p></div>
</div>
<div class="sect2">
<h3 id="_linsert">linsert</h3>
@@ -5876,6 +5880,14 @@ The legal options (which may be abbreviated) are:</p></div>
</p>
</dd>
<dt class="hdlist1">
+<tt>*string cat <em>?string1 string2 ...?</em></tt>
+</dt>
+<dd>
+<p>
+ Concatenates the given strings into a single string.
+</p>
+</dd>
+<dt class="hdlist1">
<tt><strong>string compare ?-nocase?</strong> ?<strong>-length</strong> <em>len? string1 string2</em></tt>
</dt>
<dd>
@@ -6806,11 +6818,13 @@ uid 1000 euid 1000 gid 100 egid 100</tt></pre>
<h3 id="_aio">aio</h3>
<div class="dlist"><dl>
<dt class="hdlist1">
-<tt>$handle <strong>accept</strong></tt>
+<tt>$handle <strong>accept</strong> ?addrvar?</tt>
</dt>
<dd>
<p>
- Server socket only: Accept a connection and return stream
+ Server socket only: Accept a connection and return stream.
+ If <tt><em>addrvar</em></tt> is specified, the address of the connected client is stored
+ in the named variable in the form <em>addr:port</em>. See <a href="#_socket"><strong><tt>socket</tt></strong></a> for details.
</p>
</dd>
<dt class="hdlist1">
@@ -7820,7 +7834,7 @@ tcl_platform(pathSeparator) = :</tt></pre>
</p>
</dd>
<dt class="hdlist1">
-<tt><strong>jim_argv0</strong></tt>
+<tt><strong>jim::argv0</strong></tt>
</dt>
<dd>
<p>
@@ -8163,7 +8177,7 @@ official policies, either expressed or implied, of the Jim Tcl Project.</tt></pr
<div id="footnotes"><hr /></div>
<div id="footer">
<div id="footer-text">
-Last updated 2014-05-12 11:24:57 EST
+Last updated 2014-11-17 12:21:34 EST
</div>
</div>
</body>
diff --git a/jim.c b/jim.c
index 6bc6856..7db453a 100644
--- a/jim.c
+++ b/jim.c
@@ -13444,13 +13444,13 @@ static int Jim_StringCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *a
int option;
static const char * const options[] = {
"bytelength", "length", "compare", "match", "equal", "is", "byterange", "range", "replace",
- "map", "repeat", "reverse", "index", "first", "last",
+ "map", "repeat", "reverse", "index", "first", "last", "cat",
"trim", "trimleft", "trimright", "tolower", "toupper", "totitle", NULL
};
enum
{
OPT_BYTELENGTH, OPT_LENGTH, OPT_COMPARE, OPT_MATCH, OPT_EQUAL, OPT_IS, OPT_BYTERANGE, OPT_RANGE, OPT_REPLACE,
- OPT_MAP, OPT_REPEAT, OPT_REVERSE, OPT_INDEX, OPT_FIRST, OPT_LAST,
+ OPT_MAP, OPT_REPEAT, OPT_REVERSE, OPT_INDEX, OPT_FIRST, OPT_LAST, OPT_CAT,
OPT_TRIM, OPT_TRIMLEFT, OPT_TRIMRIGHT, OPT_TOLOWER, OPT_TOUPPER, OPT_TOTITLE
};
static const char * const nocase_options[] = {
@@ -13484,6 +13484,25 @@ static int Jim_StringCoreCommand(Jim_Interp *interp, int argc, Jim_Obj *const *a
Jim_SetResultInt(interp, len);
return JIM_OK;
+ case OPT_CAT:{
+ Jim_Obj *objPtr;
+ if (argc == 3) {
+ /* optimise the one-arg case */
+ objPtr = argv[2];
+ }
+ else {
+ int i;
+
+ objPtr = Jim_NewStringObj(interp, "", 0);
+
+ for (i = 2; i < argc; i++) {
+ Jim_AppendObj(interp, objPtr, argv[i]);
+ }
+ }
+ Jim_SetResult(interp, objPtr);
+ return JIM_OK;
+ }
+
case OPT_COMPARE:
case OPT_EQUAL:
{
diff --git a/jim_tcl.txt b/jim_tcl.txt
index 53d053a..d1eb687 100644
--- a/jim_tcl.txt
+++ b/jim_tcl.txt
@@ -3815,6 +3815,9 @@ The legal options (which may be abbreviated) are:
Like `string range` except works on bytes rather than characters.
These commands are identical if UTF-8 support is not enabled.
++*string cat '?string1 string2 \...?'+::
+ Concatenates the given strings into a single string.
+
+*string compare ?-nocase?* ?*-length* 'len? string1 string2'+::
Perform a character-by-character comparison of strings +'string1'+ and
+'string2'+ in the same way as the C 'strcmp' procedure. Return
diff --git a/nshelper.tcl b/nshelper.tcl
index a31b7c0..9e617b7 100644
--- a/nshelper.tcl
+++ b/nshelper.tcl
@@ -130,7 +130,7 @@ proc {namespace info} {cmd {pattern *}} {
}
}
if {$global} {
- set result [lmap p $result { set p $prefix$p }]
+ set result [lmap p $result { string cat $prefix $p }]
}
return $result
}
diff --git a/tests/string.test b/tests/string.test
index 650088c..33723b7 100644
--- a/tests/string.test
+++ b/tests/string.test
@@ -43,7 +43,7 @@ test string-2.6 {string compare} {
string compare abcde abdef
} -1
test string-2.7 {string compare, shortest method name} {
- string c abcde ABCDE
+ string co abcde ABCDE
} 1
test string-2.8 {string compare} {
string compare abcde abcde
@@ -67,7 +67,7 @@ test string-2.13 {string compare -nocase} {
string compare -nocase abcde abdef
} -1
test string-2.14 {string compare -nocase} {
- string c -nocase abcde ABCDE
+ string co -nocase abcde ABCDE
} 0
test string-2.15 {string compare -nocase} {
string compare -nocase abcde abcde
@@ -907,4 +907,21 @@ test string-22.1 {string replace} {
string replace //test.net/path/path2?query=url?otherquery 21 end
} {//test.net/path/path2}
+test string-23.1 {string cat} {
+ string cat
+} {}
+
+test string-23.2 {string cat} {
+ string cat abc
+} {abc}
+
+test string-23.3 {string cat} {
+ string cat abc def
+} {abcdef}
+
+test string-23.4 {string cat} {
+ set abc 123
+ string cat $abc (def)
+} {123(def)}
+
testreport