D programming Language



Download 1.66 Mb.
Page40/47
Date08.01.2017
Size1.66 Mb.
#7507
1   ...   36   37   38   39   40   41   42   43   ...   47

string

To copy or not to copy?


When a function takes a string as a parameter, and returns a string, is that string the same as the input string, modified in place, or is it a modified copy of the input string? The D array convention is "copy-on-write". This means that if no modifications are done, the original string (or slices of it) can be returned. If any modifications are done, the returned string is a copy.

class StringException

Thrown on errors in string functions.

const char[] hexdigits;

"0123456789ABCDEF"

const char[] digits;

"0123456789"

const char[] octdigits;

"01234567"

const char[] lowercase;

"abcdefghijklmnopqrstuvwxyz"

const char[] uppercase;

"ABCDEFGHIJKLMNOPQRSTUVWXYZ"

const char[] letters;

"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

const char[] whitespace;

" \t\v\r\n\f"

long atoi(char[] s)

Convert string to integer.

real atof(char[] s)

Convert string to real.

int cmp(char[] s1, char[] s2)

Compare two strings. Returns:

<0 for (s1 < s2)

=0 for (s1 == s2)

>0 for (s1 > s2)

int icmp(char[] s1, char[] s2)

Same as cmp() but case insensitive.

char* toCharz(char[] string)

Converts a D array of chars to a C-style 0 terminated string.

int find(char[] s, char c)

Find first occurrance of c in string s. Return index in s where it is found. Return -1 if not found.

int rfind(char[] s, char c)

Find last occurrance of c in string s. Return index in s where it is found. Return -1 if not found.

int find(char[] s, char[] sub)

Find first occurrance of sub[] in string s[]. Return index in s[] where it is found. Return -1 if not found.

int rfind(char[] s, char[] sub)

Find last occurrance of sub in string s. Return index in s where it is found. Return -1 if not found.

char[] tolower(char[] s)

Convert string to lower case.

char[] toupper(char[] s)

Convert string to upper case.

char[] capitalize(char[] s)

Capitalize first character of string.

char[] capwords(char[] s)

Capitalize all words in string. Remove leading and trailing whitespace. Replace all sequences of whitespace with a single space.

char[] join(char[][] words, char[] sep)

Concatenate all the strings together into one string; use sep[] as the separator.

char[][] split(char[] s)

Split s[] into an array of words, using whitespace as the delimiter.

char[][] split(char[] s, char[] delim)

Split s[] into an array of words, using delim[] as the delimiter.

char[][] splitlines(char[] s)

Split s[] into an array of lines, using CR, LF, or CR-LF as the delimiter.

char[] stripl(char[] s)

char[] stripr(char[] s)

char[] strip(char[] s)

Strips leading or trailing whitespace, or both.

char[] ljustify(char[] s, int width)

char[] rjustify(char[] s, int width)

char[] center(char[] s, int width)

Left justify, right justify, or center string in field width chars wide.

char[] zfill(char[] s, int width)

Same as rjustify(), but fill with '0's.

char[] replace(char[] s, char[] from, char[] to)

Replace occurrences of from[] with to[] in s[].

char[] replaceSlice(char[] string, char[] slice, char[] replacement)

Given a string[] with a slice[] into it, replace slice[] with replacement[].

char[] insert(char[] s, int index, char[] sub)

Insert sub[] into s[] at location index.

int count(char[] s, char[] sub)

Count up all instances of sub[] in s[].

char[] expandtabs(char[] s, int tabsize)

Replace tabs with the appropriate number of spaces. tabsize is the distance between tab stops.

char[] maketrans(char[] from, char[] to)

Construct translation table for translate().

char[] translate(char[] s, char[] transtab, char[] delchars)

Translate characters in s[] using table created by maketrans(). Delete chars in delchars[].

char[] toString(uint u)

Convert uint to string.

char[] toString(char* s)

Convert C-style 0 terminated string to D string.


system



thread


The thread module defines the class Thread. Thread is the basis for writing multithreaded applications. Each thread has a unique instance of class Thread associated with it. It is important to use the Thread class to create and manage threads as the garbage collector needs to know about all the threads.

typedef ... thread_hdl

The type of the thread handle used by the operating system.

class Thread

One for each thread.

class ThreadError

Thrown for errors.

The members of Thread are:



this()

Constructor used by classes derived from Thread that override main().



this(int (*fp)(void *), void *arg)

Constructor used by classes derived from Thread that override run().



this(int delegate() dg)

Constructor used by classes derived from Thread that override run().

thread_hdl hdl;

The handle to this thread assigned by the operating system. This is set to thread_id.init if the thread hasn't been started yet.

void start();

Create a new thread and start it running. The new thread initializes itself and then calls run(). start() can only be called once.

int run(void *p);

Entry point for a thread. If not overridden, it calls the function pointer fp and argument arg passed in the constructor, or the delegate dg. The return value is the thread exit code, which is normally 0.

void wait();

Wait for this thread to terminate. Throws ThreadError if the thread hasn't begun yet or has already terminated or is called on itself.

void wait(unsigned milliseconds);

Wait for this thread to terminate or until milliseconds time has elapsed, whichever occurs first. Throws ThreadError if the thread hasn't begun yet or has already terminated or is called on itself.

TS getState();

Returns the state of the thread. The state is one of the following:



TS

Description

INITIAL

The thread hasn't been started yet.

RUNNING

The thread is running or paused.

TERMINATED

The thread has ended.

void setPriority(PRIORITY *p);

Adjust the priority of this thread.



PRIORITY

Description

INCREASE

Increase thread priority

DECREASE

Decrease thread priority

IDLE

Assign thread low priority

CRITICAL

Assign thread high priority

static Thread getThis();

Returns a reference to the Thread for the thread that called the function.

static Thread[] getAll();

Returns an array of all the threads currently running.

void pause();

Suspend execution of this thread.

void resume();

Resume execution of this thread.

static void pauseAll();

Suspend execution of all threads but this thread.

static void resumeAll();

Resume execution of all paused threads.

static void yield();

Give up the remainder of this thread's time slice.






Download 1.66 Mb.

Share with your friends:
1   ...   36   37   38   39   40   41   42   43   ...   47




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

    Main page