Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changes between Version 1 and Version 2 of RegularExpressionsExample

Show
Ignore:
Author:
jcc7 (IP: 192.149.244.9)
Timestamp:
11/21/06 19:15:24 (17 years ago)
Comment:

updated to use bool instead of bit and writefln instead of printf

Legend:

Unmodified
Added
Removed
Modified
  • RegularExpressionsExample

    v1 v2  
    1111{{{ 
    1212#!d 
     13import std.stdio : writefln; 
    1314import std.regexp; 
    1415import std.c.stdio; 
    1516 
    16 bit isalpha(char[] c) 
     17bool isalpha(char[] c) 
    1718{ 
    1819    RegExp myRegExp;     
    1920    myRegExp = new RegExp("^[a-zA-Z_]+$", "");     
    20     return cast(bit) myRegExp.test(c); 
     21    return cast(bool) myRegExp.test(c); 
    2122} 
    2223 
    23 bit isspace(char[] c) 
     24bool isspace(char[] c) 
    2425{ 
    2526     /* true if c is whitespace, false otherwise */ 
    2627 
    2728    RegExp myRegExp = new RegExp("^\\s+$", ""); 
    28     return cast(bit) myRegExp.test(c);  
     29    return cast(bool) myRegExp.test(c);  
    2930} 
    3031 
    31 bit isdigit(char[] c) 
     32bool isdigit(char[] c) 
    3233/* true if c is a decimal digit, false otherwise */ 
    3334{ 
    3435    RegExp myRegExp = new RegExp("^\\d+$", ""); 
    35     return cast(bit) myRegExp.test(c); 
     36    return cast(bool) myRegExp.test(c); 
    3637} 
    3738 
    38 bit ishexdigit(char[] c) 
     39bool ishexdigit(char[] c) 
    3940/* true if c is a hexadecimal digit, false otherwise */ 
    4041{ 
    4546} 
    4647 
    47 bit isoctdigit(char[] c) 
     48bool isoctdigit(char[] c) 
    4849/* true if c is an octal digit, false otherwise */ 
    4950{ 
    5051    RegExp myRegExp = new RegExp("^[0-7]+$", ""); 
    51     return cast(bit) myRegExp.test(c); 
     52    return cast(bool) myRegExp.test(c); 
    5253} 
    5354 
    54 bit issymbol(char[] c) 
     55bool issymbol(char[] c) 
    5556/* true if c is legal SQL symbol, false otherwise */ 
    5657{     
    5758    RegExp myRegExp = new RegExp("^[\\(\\)\\[\\]\\.,;=<>\\+\\-\\*/&\\^]+$", ""); 
    58     return cast(bit) myRegExp.test(c); 
     59    return cast(bool) myRegExp.test(c); 
    5960} 
    6061 
    6364    /* compile with the -unittest flag to run these tests */ 
    6465 
    65     printf("Testing functions...\n"); 
     66    writefln("Testing functions..."); 
    6667     
    6768    assert(isalpha("a") && isalpha("A") && !isalpha("9") && isalpha("_") && isalpha("R") && !isalpha("&")); 
    7980    assert(isspace(" ")  && isspace("\t") && !isspace("o")  && !isspace(".")  && !isspace("5")); 
    8081 
    81     printf("Functions tested successfully.\n"); 
     82    writefln("Functions tested successfully."); 
    8283} 
    8384 
    8687    /* Compile with the -debug flag for this statement to run. */ 
    8788 
    88     debug printf("Main Program.\n"); 
     89    debug writefln("Main Program."); 
    8990} 
    9091}}} 
    9192 
    92 == Source == 
    9393 
    94 || Link || http://www.dsource.org/tutorials/index.php?show_example=58 || 
    95 || Posted by || jcc7 || 
    96 || Date/Time || Fri May 14, 2004 10:52 pm || 
     94 
     95== Sample Batch File == 
     96 
     97{{{ 
     98@echo off 
     99set pgm=RegularExpressionsExample 
     100dmd %pgm%.d -unittest -debug 
     101%pgm%.exe 
     102pause 
     103erase %pgm%.obj 
     104erase %pgm%.map 
     105}}} 
     106 
     107== Console Output == 
     108 
     109(using `unittest` and `debug` switches) 
     110 
     111{{{ 
     112Testing functions... 
     113Functions tested successfully. 
     114Main Program. 
     115}}} 
     116 
     117== Testing == 
     118 
     119Tested with DMD 0.174 on Windows 2000. 
     120 
     121== More Information == 
     122 
     123For more information about Regular Expressions in Phobos, see [http://www.digitalmars.com/d/phobos/std_regexp.html std.regexp].