---
name: "ACE_SString"
section: "3"
platform: "linux"
package: "libace-doc"
version: "5.0.7-4"
release: "Debian 2.2 (Potato)"
platforms: ["linux"]
url: "https://new.carta.tech/ACE_SString"
---

# ACE\_SString(3)

A very Simple String ACE\_SString class. This is not a general-purpose string class, and you should probably consider using ACE\_CString is you don't understand why this class exists...

## NAME

ACE\_SString -  A very Simple String ACE\_SString class.  This is not a general-purpose string class, and you should probably consider using ACE\_CString is you don't understand why this class exists...

## SYNOPSIS

```
#include <ace/SString.h>
class ACE_SString
{
  public:
    static const int npos;
    ACE_SString (ACE_Allocator *alloc = 0);
    ACE_SString (const char *s, ACE_Allocator *alloc = 0);
    ACE_SString (const char *s, size_t len, ACE_Allocator *alloc = 0);
    ACE_SString (const ACE_SString &);
    ACE_SString (char c, ACE_Allocator *alloc = 0);
    ~ACE_SString (void);
    char operator [] (size_t slot) const;
    char &operator [] (size_t slot);
    ACE_SString &operator = (const ACE_SString &);
    ACE_SString substring (size_t offset, ssize_t length = -1) const;
    ACE_SString substr (size_t offset, ssize_t length = -1) const;
    u_long hash (void) const;
    size_t length (void) const;
    void rep (char *s);
    const char *rep (void) const;
    const char *fast_rep (void) const;
    const char *c_str (void) const;
    int strstr (const ACE_SString &s) const;
    int find (const ACE_SString &str, int pos = 0) const;
    int find (const char *s, int pos = 0) const;
    int find (char c, int pos = 0) const;
    int rfind (char c, int pos = npos) const;
    int operator == (const ACE_SString &s) const;
    int operator < (const ACE_SString &s) const;
    int operator > (const ACE_SString &s) const;
    int operator != (const ACE_SString &s) const;
    int compare (const ACE_SString &s) const;
    void dump (void) const;
    ACE_ALLOC_HOOK_DECLARE;
  private:
    ACE_Allocator *allocator_;
    size_t len_;
    char *rep_;
};
```

## DESCRIPTION

This class is only intended for use with applications that understand how it works.  In particular, its destructor does not deallocate its memory when it is destroyed...  We need this class since the ACE\_Map\_Manager requires an object that supports the operator == and operator !=.  This class uses an ACE\_Allocator to allocate memory.  The user can make this a persistant class by providing an ACE\_Allocator with a persistable memory pool.

## PUBLIC MEMBERS

```
static const int npos;
```

No position constant

```
ACE_SString (ACE_Allocator *alloc = 0);
```

Default constructor.

```
ACE_SString (const char *s, ACE_Allocator *alloc = 0);
```

Constructor that copies s into dynamically allocated memory.

```
ACE_SString (const char *s, size_t len, ACE_Allocator *alloc = 0);
```

Constructor that copies len chars of s into dynamically allocated memory (will NUL terminate the result).

```
ACE_SString (const ACE_SString &);
```

Copy constructor.

```
ACE_SString (char c, ACE_Allocator *alloc = 0);
```

Constructor that copies c into dynamically allocated memory.

```
~ACE_SString (void);
```

Default dtor.

```
char operator [] (size_t slot) const;
```

Return the slot'th character in the string (doesn't perform bounds checking).

```
char &operator [] (size_t slot);
```

Return the slot'th character by reference in the string (doesn't perform bounds checking).

```
ACE_SString &operator = (const ACE_SString &);
```

Assignment operator (does copy memory).

```
ACE_SString substring (size_t offset, ssize_t length = -1) const;
```

Return a substring given an offset and length, if length == -1 use rest of str return empty substring if offset or offset/length are invalid

```
ACE_SString substr (size_t offset, ssize_t length = -1) const;
```

Same as substring

```
u_long hash (void) const;
```

Returns a hash value for this string.

```
size_t length (void) const;
```

Return the length of the string.

```
void rep (char *s);
```

Set the underlying pointer.  Since this does not copy memory or delete existing memory use with extreme caution!!!

```
const char *rep (void) const;
```

Get the underlying pointer.

```
const char *fast_rep (void) const;
```

Get the underlying pointer.

```
const char *c_str (void) const;
```

Same as STL String's c\_str and fast\_rep.

```
int strstr (const ACE_SString &s) const;
```

Comparison operator that will match substrings.  Returns the slot of the first location that matches, else -1.

```
int find (const ACE_SString &str, int pos = 0) const;
```

Find str starting at pos.  Returns the slot of the first location that matches, else npos.

```
int find (const char *s, int pos = 0) const;
```

Find s starting at pos.  Returns the slot of the first location that matches, else npos.

```
int find (char c, int pos = 0) const;
```

Find c starting at pos.  Returns the slot of the first location that matches, else npos.

```
int rfind (char c, int pos = npos) const;
```

Find c starting at pos (counting from the end).  Returns the slot of the first location that matches, else npos.

```
int operator == (const ACE_SString &s) const;
```

Equality comparison operator (must match entire string).

```
int operator < (const ACE_SString &s) const;
```

Less than comparison operator.

```
int operator > (const ACE_SString &s) const;
```

Greater than comparison operator.

```
int operator != (const ACE_SString &s) const;
```

Inequality comparison operator.

```
int compare (const ACE_SString &s) const;
```

Performs a strcmp-style comparison.

```
void dump (void) const;
```

Dump the state of an object.

```
ACE_ALLOC_HOOK_DECLARE;
```

Declare the dynamic allocation hooks.

## PRIVATE MEMBERS

```
ACE_Allocator *allocator_;
```

Pointer to a memory allocator.

```
size_t len_;
```

Length of the ACE\_SString (not counting the trailing '\\0').

```
char *rep_;
```

Pointer to data.

## AUTHOR

Douglas C. Schmidt (schmidt@cs.wustl.edu)

## LIBRARY

ace
