Logo Search packages:      
Sourcecode: yate version File versions  Download package

String & String::assign ( const char *  value,
int  len = -1 
)

Assigns a new value to the string from a character block.

Parameters:
value New value of the string
len Length of the data to copy, -1 for full string

Definition at line 252 of file String.cpp.

References changed(), clear(), and TelEngine::Debug().

Referenced by operator>>(), startSkip(), String(), and trimBlanks().

{
    if (len && value && *value) {
      if (len < 0)
          len = ::strlen(value);
      else {
          int l = 0;
          for (const char* p = value; l < len; l++)
            if (!*p++)
                break;
          len = l;
      }
      if (value != m_string || len != (int)m_length) {
          char *data = (char *) ::malloc(len+1);
          if (data) {
            ::memcpy(data,value,len);
            data[len] = 0;
            char *odata = m_string;
            m_string = data;
            changed();
            if (odata)
                ::free(odata);
          }
          else
            Debug("String",DebugFail,"malloc(%d) returned NULL!",len+1);
      }
    }
    else
      clear();
    return *this;
}


Generated by  Doxygen 1.6.0   Back to index