Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #623 (new enhancement)

Opened 17 years ago

Last modified 14 years ago

Add a string copy function

Reported by: keinfarbton Assigned to: kris
Priority: normal Milestone: 2.0
Component: Tango Version: 0.99.1 RC4 Keep
Keywords: triage Cc: larsivi, sean

Description

Probably I really missed it.

I cannot find a copy function. Basically I want to make this

char[200] buf;
char[] res = Layout.sprint( buf, "{}", getString());
// res is a slice of buf.

So probably text.Util would be a good place for it?

T[] stringcopy(T)( T[] buf, T[] src ){
    if( buf.length < src.length ){
        buf[] = src[0 .. buf.length ];
        return buf;
    }
    else{
        buf[ 0 .. src.length ] = src[];
        return buf[ 0 .. src.length ];
    }
}

Change History

09/29/07 19:36:26 changed by kris

  • status changed from new to assigned.
  • cc set to larsivi, sean.
  • milestone changed from 0.99.2 RC5 to 1.0.
char[200] buf;
char[] res = Layout.sprint( buf, "{}", getString());
// res is a slice of buf.

Not quite sure what you're asking for, Frank? Layout.sprint() already operates as you illustrate

09/30/07 15:10:27 changed by keinfarbton

I am asking for this stringcopy function, without the need to go over the layout object/method with a format string.

09/30/07 16:52:12 changed by kris

  • status changed from assigned to new.
  • owner changed from kris to sean.

Hrm, I thought array syntax was supposed to take care of that directly? I guess one could be added to the Array templates, if Sean thinks that's appropriate?

01/17/08 15:08:07 changed by sean

The array syntax does take care of this. You can do "a[] = b[]" or define ranges to copy or whatever. Is a function really needed?

05/24/08 21:32:32 changed by keinfarbton

05/24/08 21:48:05 changed by larsivi

  • keywords set to triage.

Yes, but

http://codepad.org/P16lT4sa

But essentially you want memcpy?

05/24/08 22:01:06 changed by keinfarbton

no, i am asking for a copy funtion that does restrict the copy-length to the supplied buffer.

05/24/08 23:05:57 changed by larsivi

Hmm, ok, and I guess we've established that array copy doesn't currently do this. The change in the runtime would be simple, but I don't know if the spec would allow it (although I see no real reason to disallow it).

11/09/09 01:16:06 changed by kris

  • owner changed from sean to fawzi.

11/29/09 12:33:56 changed by fawzi

  • owner changed from fawzi to kris.

04/24/10 22:22:11 changed by kris

  • milestone changed from 1.0 to 2.0.