Tamarin:Strings: Difference between revisions

→‎Additional String methods: Change getIndependentString() to fixDependentString(), to match the code
m (→‎Appending data: fix typo)
(→‎Additional String methods: Change getIndependentString() to fixDependentString(), to match the code)
 
Line 102: Line 102:
   if (s->indexOfLatin1(":")) < 0) ...
   if (s->indexOfLatin1(":")) < 0) ...


The <tt>getIndependentString()</tt> converts a substring to a normal string. This is handy if the string needs to live for a long time, but if you do not want the master of a dependent substring to live for that long.
The <tt>fixDependentString()</tt> function converts a substring to a normal string. This is handy if the string needs to live for a long time, but if you do not want the master of a dependent substring to live for that long.


Example:
Example:
Line 108: Line 108:
   Stringp xml = parseVeryLargeXMLFile();
   Stringp xml = parseVeryLargeXMLFile();
   Stringp start = xml->substr (0, 3);
   Stringp start = xml->substr (0, 3);
   // if start was to be stored anywhere, the entire, hige XML string would remain alive
   // if start was to be stored anywhere, the entire, huge XML string would remain alive
   // unless makeDynamic was called
   // unless fixDependentString was called
   start = start->getIndependentString();
   start->fixDependentString();
    
    
The <tt>makeDynamic()</tt> converts a string with a static buffer, or a string that is a substring to a string with a dynamic buffer.
The <tt>makeDynamic()</tt> function converts a string with a static buffer, or a string that is a substring to a string with a dynamic buffer.
10

edits