wasCSharpSQLite – Blame information for rev

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 /*
2 * LreplaceCmd.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: LreplaceCmd.java,v 1.5 2003/01/09 02:15:39 mdejong Exp $
14 *
15 */
16 using System;
17 namespace tcl.lang
18 {
19  
20 /// <summary> This class implements the built-in "lreplace" command in Tcl.</summary>
21  
22 class LreplaceCmd : 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 ?element element ...?" );
33 }
34 int size = TclList.getLength( interp, argv[1] );
35 int first = Util.getIntForIndex( interp, argv[2], size - 1 );
36 int last = Util.getIntForIndex( interp, argv[3], size - 1 );
37 int numToDelete;
38  
39 if ( first < 0 )
40 {
41 first = 0;
42 }
43  
44 // Complain if the user asked for a start element that is greater
45 // than the list length. This won't ever trigger for the "end*"
46 // case as that will be properly constrained by getIntForIndex
47 // because we use size-1 (to allow for replacing the last elem).
48  
49 if ( ( first >= size ) && ( size > 0 ) )
50 {
51  
52 throw new TclException( interp, "list doesn't contain element " + argv[2] );
53 }
54 if ( last >= size )
55 {
56 last = size - 1;
57 }
58 if ( first <= last )
59 {
60 numToDelete = ( last - first + 1 );
61 }
62 else
63 {
64 numToDelete = 0;
65 }
66  
67 TclObject list = argv[1];
68 bool isDuplicate = false;
69  
70 // If the list object is unshared we can modify it directly. Otherwise
71 // we create a copy to modify: this is "copy on write".
72  
73 if ( list.Shared )
74 {
75 list = list.duplicate();
76 isDuplicate = true;
77 }
78  
79 try
80 {
81 TclList.replace( interp, list, first, numToDelete, argv, 4, argv.Length - 1 );
82 interp.setResult( list );
83 }
84 catch ( TclException e )
85 {
86 if ( isDuplicate )
87 {
88 list.release();
89 }
90 throw;
91 }
92 return TCL.CompletionCode.RETURN;
93 }
94 }
95 }