D programming Language



Download 1.66 Mb.
Page38/47
Date08.01.2017
Size1.66 Mb.
#7507
1   ...   34   35   36   37   38   39   40   41   ...   47

regexp


RegExp is a D class to handle regular expressions. Regular expressions are a powerful method of string pattern matching. The RegExp class is the core foundation for adding powerful string pattern matching capabilities to programs like grep, text editors, awk, sed, etc. The regular expression language used is the same as that commonly used, however, some of the very advanced forms may behave slightly differently.

The RegExp class has these methods:



this(char[] pattern, char[] attributes)

Create a new RegExp object. Compile pattern[] with attributes[] into an internal form for fast execution. Throws a RegExpError if there are any compilation errors.

char[][] split(char[] string)

Split string[] into an array of strings, using the regular expression as the separator. Returns array of slices in string[].

int search(char[] string)

Search string[] for match with regular expression.



Returns

Description

>=0

index of match

-1

no match

char[][] match(char[] string)

Search string[] for match.



Attribute

Returns

global

same as call to exec(string)

not global

array of all matches

char[][] exec(char[] string)

Search string[] for next match. Returns array of slices into string[] representing matches.

int test(char[] string)

Search string[] for next match.



Returns

Description

0

no match

!=0

match

char[] replace(char[] string, char[] format)

Find regular expression matches in string[]. Replace those matches with a new string composed of format[] merged with the result of the matches.



Attribute

Action

global

replace all matches

not global

replace first match

Returns the new string.

char[] replace(char[] format)

After a match is found with test(), this function will take the match results and, using the format[] string, generate and return a new string. The format commands are:


Format

Description

$$

insert $

$&

insert the matched substring

$`

insert the string that precedes the match

$'

insert the string that following the match

$n

replace with the nth parenthesized match, n is 1..9







$nn

replace with the nnth parenthesized match, nn is 01..99







$

insert $

char[] replaceOld(char[] format)

Like replace(char[] format), but uses old style formatting:



Format

Description

&

replace with the match

\n

replace with the nth parenthesized match, n is 1..9

\c

replace with char c.


stdint


D constrains integral types to specific sizes. But efficiency of different sizes varies from machine to machine, pointer sizes vary, and the maximum integer size varies. stdint offers a portable way of trading off size vs efficiency, in a manner compatible with the stdint.h definitions in C.

The exact aliases are types of exactly the specified number of bits. The at least aliases are at least the specified number of bits large, and can be larger. The fast aliases are the fastest integral type supported by the processor that is at least as wide as the specified number of bits.



The aliases are:

Exact Alias

Description

At Least Alias

Description

Fast Alias

Description

int8_t

exactly 8 bits signed

int_least8_t

at least 8 bits signed

int_fast8_t

fast 8 bits signed

uint8_t

exactly 8 bits unsigned

uint_least8_t

at least 8 bits unsigned

uint_fast8_t

fast 8 bits unsigned

int16_t

exactly 16 bits signed

int_least16_t

at least 16 bits signed

int_fast16_t

fast 16 bits signed

uint16_t

exactly 16 bits unsigned

uint_least16_t

at least 16 bits unsigned

uint_fast16_t

fast 16 bits unsigned

int32_t

exactly 32 bits signed

int_least32_t

at least 32 bits signed

int_fast32_t

fast 32 bits signed

uint32_t

exactly 32 bits unsigned

uint_least32_t

at least 32 bits unsigned

uint_fast32_t

fast 32 bits unsigned

int64_t

exactly 64 bits signed

int_least64_t

at least 64 bits signed

int_fast64_t

fast 64 bits signed

uint64_t

exactly 64 bits unsigned

uint_least64_t

at least 64 bits unsigned

uint_fast64_t

fast 64 bits unsigned

The ptr aliases are integral types guaranteed to be large enough to hold a pointer without losing bits:

Alias

Description

intptr_t

signed integral type large enough to hold a pointer

uintptr_t

unsigned integral type large enough to hold a pointer

The max aliases are the largest integral types:

Alias

Description

intmax_t

the largest signed integral type

uintmax_t

the largest unsigned integral type




Download 1.66 Mb.

Share with your friends:
1   ...   34   35   36   37   38   39   40   41   ...   47




The database is protected by copyright ©ininet.org 2024
send message

    Main page