MCPcopy Create free account
hub / github.com/TorqueGameEngines/Torque3D / updateToken

Method updateToken

Engine/source/console/persistenceManager.cpp:905–997  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

903}
904
905void PersistenceManager::updateToken( const U32 lineNumber, const U32 linePosition, const U32 oldValueLen, const char* newValue, bool addQuotes )
906{
907 // Make sure we have a valid lineNumber
908 if (lineNumber < 0 || linePosition < 0 ||
909 lineNumber >= mLineBuffer.size())
910 return;
911
912 // Grab the line that the value is on
913 const char* line = mLineBuffer[lineNumber];
914
915 U32 newValueLen = ( newValue ) ? dStrlen(newValue) : 0;
916
917 // Make sure we have a valid linePosition
918 if (linePosition >= dStrlen(line) ||
919 linePosition + oldValueLen > dStrlen(line))
920 return;
921
922 // Get all of the characters up to the value position
923 U32 preStringLen = linePosition;
924
925 bool needQuotes = false;
926 if( addQuotes && line[ linePosition - 1 ] != '"' )
927 {
928 preStringLen ++;
929 needQuotes = true;
930 }
931
932 char* preString = ( char* ) dMalloc( preStringLen + 1 );
933 dMemcpy( preString, line, linePosition );
934
935 if( needQuotes )
936 {
937 preString[ linePosition ] = '"';
938 preString[ linePosition + 1 ] = 0;
939 }
940 else
941 preString[ linePosition ] = 0;
942
943 // Get all of the characters that occur after the value
944
945 const char* postStringSrc = line + linePosition + oldValueLen;
946 U32 postStringLen = dStrlen( postStringSrc );
947 if( needQuotes )
948 postStringLen ++;
949
950 char* postString = ( char* ) dMalloc( postStringLen + 1 );
951 if( needQuotes )
952 postString[ 0 ] = '"';
953 dStrcpy( &postString[ needQuotes ? 1 : 0 ], postStringSrc, postStringLen + (needQuotes ? 0 : 1) );
954 postString[ postStringLen ] = 0;
955
956 // Calculate the length of our new line
957 U32 newLineLen = 0;
958
959 newLineLen += preStringLen;
960 newLineLen += newValueLen;
961 newLineLen += postStringLen;
962

Callers

nothing calls this directly

Calls 6

dStrcpyFunction · 0.85
dStrcatFunction · 0.85
dStrlenFunction · 0.50
dMemcpyFunction · 0.50
dFreeFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected