wasCSharpSQLite – Blame information for rev

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 /*
2 * LrangeCmd.java
3 *
4 * Copyright (c) 1997 Cornell University.
5 * Copyright (c) 1997 Sun Microsystems, Inc.
6 *
7 * See the file "license.terms" for information on usage and
8 * redistribution of this file, and for a DISCLAIMER OF ALL
9 * WARRANTIES.
10 *
11 * Included in SQLite3 port to C# for use in testharness only; 2008 Noah B Hart
12 *
13 * RCS @(#) $Id: LrangeCmd.java,v 1.2 2000/03/17 23:31:30 mo Exp $
14 *
15 */
16 using System;
17 namespace tcl.lang
18 {
19  
20 /// <summary> This class implements the built-in "lrange" command in Tcl.</summary>
21  
22 class LrangeCmd : Command
23 {
24 /// <summary> See Tcl user documentation for details.</summary>
25 /// <exception cref=""> TclException If incorrect number of arguments.
26 /// </exception>
27  
28 public TCL.CompletionCode cmdProc( Interp interp, TclObject[] argv )
29 {
30 if ( argv.Length != 4 )
31 {
32 throw new TclNumArgsException( interp, 1, argv, "list first last" );
33 }
34  
35 int size = TclList.getLength( interp, argv[1] );
36 int first;
37 int last;
38  
39 first = Util.getIntForIndex( interp, argv[2], size - 1 );
40 last = Util.getIntForIndex( interp, argv[3], size - 1 );
41  
42 if ( last < 0 )
43 {
44 interp.resetResult();
45 return TCL.CompletionCode.RETURN;
46 }
47 if ( first >= size )
48 {
49 interp.resetResult();
50 return TCL.CompletionCode.RETURN;
51 }
52 if ( first <= 0 && last >= size )
53 {
54 interp.setResult( argv[1] );
55 return TCL.CompletionCode.RETURN;
56 }
57  
58 if ( first < 0 )
59 {
60 first = 0;
61 }
62 if ( first >= size )
63 {
64 first = size - 1;
65 }
66 if ( last < 0 )
67 {
68 last = 0;
69 }
70 if ( last >= size )
71 {
72 last = size - 1;
73 }
74 if ( first > last )
75 {
76 interp.resetResult();
77 return TCL.CompletionCode.RETURN;
78 }
79  
80 TclObject list = TclList.newInstance();
81  
82 list.preserve();
83 try
84 {
85 for ( int i = first; i <= last; i++ )
86 {
87 TclList.append( interp, list, TclList.index( interp, argv[1], i ) );
88 }
89 interp.setResult( list );
90 }
91 finally
92 {
93 list.release();
94 }
95 return TCL.CompletionCode.RETURN;
96 }
97 }
98 }