PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/TCL/src/commands/LinsertCmd.cs

https://bitbucket.org/eumario/csharp-sqlite
C# | 65 lines | 37 code | 7 blank | 21 comment | 3 complexity | 5501538d439125aab222d6074861bfc7 MD5 | raw file
  1. /*
  2. * LinsertCmd.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: LinsertCmd.java,v 1.3 2003/01/09 02:15:39 mdejong Exp $
  14. *
  15. */
  16. using System;
  17. namespace tcl.lang
  18. {
  19. /// <summary> This class implements the built-in "linsert" command in Tcl.</summary>
  20. class LinsertCmd : Command
  21. {
  22. /// <summary> See Tcl user documentation for details.</summary>
  23. /// <exception cref=""> TclException If incorrect number of arguments.
  24. /// </exception>
  25. public TCL.CompletionCode cmdProc( Interp interp, TclObject[] argv )
  26. {
  27. if ( argv.Length < 4 )
  28. {
  29. throw new TclNumArgsException( interp, 1, argv, "list index element ?element ...?" );
  30. }
  31. int size = TclList.getLength( interp, argv[1] );
  32. int index = Util.getIntForIndex( interp, argv[2], size );
  33. TclObject list = argv[1];
  34. bool isDuplicate = false;
  35. // If the list object is unshared we can modify it directly. Otherwise
  36. // we create a copy to modify: this is "copy on write".
  37. if ( list.Shared )
  38. {
  39. list = list.duplicate();
  40. isDuplicate = true;
  41. }
  42. try
  43. {
  44. TclList.insert( interp, list, index, argv, 3, argv.Length - 1 );
  45. interp.setResult( list );
  46. }
  47. catch ( TclException e )
  48. {
  49. if ( isDuplicate )
  50. {
  51. list.release();
  52. }
  53. throw;
  54. }
  55. return TCL.CompletionCode.RETURN;
  56. }
  57. }
  58. }