Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix issue 9622 - Range violation in rdmd #47

Merged
merged 1 commit into from

3 participants

Andrei Alexandrescu monarch dodra Alex Rønne Petersen
Alex Rønne Petersen alexrp merged commit 9fc4f6a into from
monarch dodra monarchdodra commented on the diff
@@ -41,7 +41,7 @@ private string compiler = defaultCompiler;
int main(string[] args)
{
- //writeln("Invoked with: ", map!(q{a ~ ", "})(args));
+ //writeln("Invoked with: ", args);
monarch dodra Collaborator

Just want to point out that If you really want a comma separated list in text format, then the "best" (easiest) way would be using the formatted write with list syntax:

    writefln("Invoked with: %(%s, %).", args);
rdmd main.d hello "C:\My Folder" world
Invoked with: "main.exe", "hello", "C:\\My Folder", "world".

Using the "raw" range means you data will be "bracket enclosed":

Invoked with: ["main.exe", "hello", "C:\\My Folder", "world"].

The code is commented, so it doesn't matter much anyways, but just wanted to point it out.

Andrei Alexandrescu Owner
andralex added a note

Thanks, good point. This reminds me I've forever wanted to add a %D format specifier to format that causes data to be formatted closest to a D data definition.

monarch dodra Collaborator

That's what %s does by default when there is no provided toString function, right? The point of %D would be to explicitly bypass the toString?

I think this thread I just started in learn is actually specifically asking for this feature:
http://forum.dlang.org/thread/lljftxptrgrltcpaszgf@forum.dlang.org

Basically, I want to print a string according to how it would look in D.

Andrei Alexandrescu Owner
andralex added a note

Yah, the simplest case is printing a string with escaped characters etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Deleted user Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Deleted user Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Deleted user Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Deleted user Unknown referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 1, 2013
  1. Andrei Alexandrescu
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 2 deletions.
  1. +4 −2 rdmd.d
6 rdmd.d
View
@@ -41,7 +41,7 @@ private string compiler = defaultCompiler;
int main(string[] args)
{
- //writeln("Invoked with: ", map!(q{a ~ ", "})(args));
+ //writeln("Invoked with: ", args);
monarch dodra Collaborator

Just want to point out that If you really want a comma separated list in text format, then the "best" (easiest) way would be using the formatted write with list syntax:

    writefln("Invoked with: %(%s, %).", args);
rdmd main.d hello "C:\My Folder" world
Invoked with: "main.exe", "hello", "C:\\My Folder", "world".

Using the "raw" range means you data will be "bracket enclosed":

Invoked with: ["main.exe", "hello", "C:\\My Folder", "world"].

The code is commented, so it doesn't matter much anyways, but just wanted to point it out.

Andrei Alexandrescu Owner
andralex added a note

Thanks, good point. This reminds me I've forever wanted to add a %D format specifier to format that causes data to be formatted closest to a D data definition.

monarch dodra Collaborator

That's what %s does by default when there is no provided toString function, right? The point of %D would be to explicitly bypass the toString?

I think this thread I just started in learn is actually specifically asking for this feature:
http://forum.dlang.org/thread/lljftxptrgrltcpaszgf@forum.dlang.org

Basically, I want to print a string according to how it would look in D.

Andrei Alexandrescu Owner
andralex added a note

Yah, the simplest case is printing a string with escaped characters etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
if (args.length > 1 && args[1].startsWith("--shebang ", "--shebang="))
{
// multiple options wrapped in one
@@ -148,6 +148,7 @@ int main(string[] args)
// Parse the program line - first find the program to run
programPos = indexOfProgram(args);
+ assert(programPos > 0);
if (programPos == args.length)
{
write(helpString);
@@ -159,7 +160,8 @@ int main(string[] args)
exeDirname = root.dirName,
programArgs = args[programPos + 1 .. $];
args = args[0 .. programPos];
- auto compilerFlags = args[1 .. programPos - 1];
+ assert(args.length >= 1);
+ auto compilerFlags = args[1 .. max(1, programPos - 1)];
// --build-only implies the user would like a binary in the program's directory
if (buildOnly && !exe)
Something went wrong with that request. Please try again.