MString Class Reference
[OpenMaya - API module for common classes]

#include <MString.h>
Collaboration diagram for MString:
Collaboration graph
[legend]

List of all members.


Detailed Description

Manipulate strings.

The MString class implements a string class, and is used to pass all string arguments to Maya API methods.

The MString class supports localized strings. Use of the MString class to store and manipulate strings largely insulates the code from locale-dependent processing. Code that uses the class and its methods will in most cases operate seamlessly in both multibyte and single-byte environments. Knowledge of the underlying string storage mechanism or encoding is not required to use the class, and assumptions about this should not be made by the calling code.

Unless otherwise indicated, MString methods accepting or returning string contents via character buffers (char *) use the convention that the string contents are in the locale's native multibyte encoding. Methods which explicitly support other common encodings and representations such as UTF-8 and wchar_t are also provided. Code that manipulates string contents should use the multibyte-safe methods provided by the class. Refer to documentation on individual MString methods for more information.

Examples:

animExportUtil.cpp, animExportUtil.h, animFileExport.cpp, animFileExport.h, animFileUtils.cpp, animFileUtils.h, animImportExport.cpp, animImportExport.h, animInfoCmd.cpp, anisotropicShader.cpp, apiMeshData.cpp, apiMeshData.h, asciiToBinary.cpp, AshliPluginMain.cpp, backfillShader.cpp, blindComplexDataCmd.cpp, blindDataPluginMain.cpp, blindDoubleDataCmd.cpp, blindShortDataCmd.cpp, brickShader.cpp, cellShader.cpp, cgfxAttrDef.cpp, cgfxAttrDef.h, cgfxEffectDef.cpp, cgfxEffectDef.h, cgfxFindImage.cpp, cgfxFindImage.h, cgfxShaderCmd.cpp, cgfxShaderCmd.h, cgfxShaderNode.cpp, cgfxShaderNode.h, checkerShader.cpp, cleanPerFaceAssignmentCmd.cpp, clearcoat.cpp, closestPointCmd.cpp, closestPointOnCurveCmd.cpp, closestPointOnCurveCmd.h, closestPointOnNurbsSurfaceCmd.cpp, clothPaintAttrCmd.cpp, componentScaleManip.cpp, compositingShader.cpp, conditionTest.cpp, contrastShader.cpp, convertBumpCmd.cpp, convertEdgesToFacesCmd.cpp, convertVerticesToEdgesCmd.cpp, convertVerticesToFacesCmd.cpp, createClipCmd.cpp, customAttrManip.cpp, customImagePlane.cpp, cvColorShader.cpp, cvPosCmd.cpp, D3DGeometryItem.cpp, D3DResourceManager.cpp, D3DResourceManager.h, D3DTextureItem.cpp, D3DViewportRenderer.cpp, dagMessageCmd.cpp, dagPoseInfoCmd.cpp, ddsFloatReader.cpp, deletedMsgCmd.cpp, depthShader.cpp, displacementShader.cpp, dynExprField.cpp, eventTest.cpp, exampleMRampAttribute.cpp, exportJointClusterDataCmd.cpp, exportSkinClusterDataCmd.cpp, fileIOMsgCmd.cpp, filteredAsciiFile.cpp, findFileTexturesCmd.cpp, findTexturesPerPolygonCmd.cpp, flameShader.cpp, fluidInfoCmd.cpp, footPrintManip.cpp, fxManagerCmd.cpp, fxManagerCmd.h, gammaShader.cpp, geometryCacheBlockBase.cpp, geometryCacheBlockBase.h, geometryCacheBlockDVAData.cpp, geometryCacheBlockDVAData.h, geometryCacheBlockFVAData.cpp, geometryCacheBlockFVAData.h, geometryCacheBlockIntData.cpp, geometryCacheBlockIntData.h, geometryCacheBlockStringData.cpp, geometryCacheBlockStringData.h, geometryCacheConverter.cpp, geometryCacheFile.cpp, geometryCacheFile.h, geomShader.cpp, getAttrAffectsCmd.cpp, glExtensions.cpp, GLSLShaderNode.cpp, GLSLShaderNode.h, helix2Cmd.cpp, helixCmd.cpp, helixTool.cpp, hlslPluginMain.cpp, hlslShader.cpp, hlslShader.h, hwAnisotropicShader_NV20.cpp, hwAnisotropicShader_NV20.h, hwColorPerVertexShader.cpp, hwDecalBumpShader_NV20.cpp, hwDecalBumpShader_NV20.h, hwManagedTextureShader.cpp, hwPhongShader.cpp, hwPhongShaderBehavior.cpp, hwReflectBumpShader_NV20.cpp, hwReflectBumpShader_NV20.h, hwRefractReflectShader_NV20.cpp, hwRefractReflectShader_NV20.h, hwRenderPostEffect.cpp, hwToonShader_NV20.cpp, hwToonShader_NV20.h, hwUnlitShader.cpp, hwUnlitShader.h, iffInfoCmd.cpp, iffPixelCmd.cpp, iffPpmCmd.cpp, iffreader.cpp, iffreader.h, instancerListCmd.cpp, interpShader.cpp, intersectCmd.cpp, intersectOnNurbsSurfaceCmd.cpp, jlcVcrDevice.cpp, lambertShader.cpp, latticeNoiseCmd.cpp, lavaShader.cpp, lepTranslator.cpp, lightShader.cpp, lineManipContainer.cpp, lockEvent.cpp, maTranslator.cpp, meshRemapCmd.cpp, meshRemapTool.h, meshReorderCmd.cpp, meshReorderTool.h, mixtureShader.cpp, motionTraceCmd.cpp, moveManip.cpp, moveNumericTool.cpp, moveTool.cpp, MTexture.cpp, MTexture.h, MTextureCache.cpp, MTextureCache.h, narrowPolyViewer.cpp, narrowPolyViewer.h, nodeCreatedCBCmd.cpp, nodeCreatedCBCmd.h, nodeInfoCmd.cpp, NodeMonitor.cpp, NodeMonitor.h, noiseShader.cpp, objExport.cpp, offsetNode.cpp, OpenEXR.cpp, OpenGLViewportRenderer.cpp, particlePathsCmd.cpp, particleSystemInfoCmd.cpp, peltOverlapCmd.cpp, pfxInfoCmd.cpp, phongShader.cpp, pickCmd.cpp, pluginMain.cpp, pnTrianglesNode.cpp, pointOnMeshCmd.cpp, pointOnMeshCmd.h, polyExporter.cpp, polyExporter.h, polyModifierCmd.cpp, polyModifierCmd.h, polyPrimitiveCmd.cpp, polyRawExporter.cpp, polyRawExporter.h, polyRawWriter.cpp, polyRawWriter.h, polyWriter.cpp, polyWriter.h, polyX3DExporter.cpp, polyX3DExporter.h, polyX3DWriter.cpp, polyX3DWriter.h, progressWindowCmd.cpp, readAndWrite.cpp, referenceQueryCmd.cpp, renderAccessNode.cpp, rotateManip.cpp, sampleCmd.cpp, sampleParticles.cpp, scanDagCmd.cpp, scanDagSyntax.cpp, ShadingConnection.cpp, ShadingConnection.h, shadowMatteShader.cpp, ShapeMonitor.cpp, ShapeMonitor.h, shellNode.cpp, shiftNode.cpp, simpleImageFile.cpp, simpleSolverNode.cpp, slopeShader.cpp, slopeShaderBehavior.cpp, solidCheckerShader.cpp, spiralAnimCurveCmd.cpp, splitUVFtyAction.cpp, squareScaleManipContext.cpp, stringFormatNode.cpp, surfaceBumpManip.cpp, surfaceCreate.cpp, surfaceTwist.cpp, swissArmyManip.cpp, testNobjectNode.cpp, testNucleusNode.cpp, threadTestCmd.cpp, threadTestWithLocksCmd.cpp, tiffFloatReader.cpp, undoRedoMsgCmd.cpp, userMsgCmd.cpp, viewCallbackTest.cpp, viewCaptureCmd.cpp, volumeLightCmd.cpp, volumeShader.cpp, whatisCmd.cpp, and XmlGeometryCache.cpp.


Public Member Functions

  MString ()
  MString (const char *charString)
  MString (const wchar_t *charString)
  MString (const char *charString, int charLength)
  MString (const wchar_t *charString, int wcharLength)
  MString (const MString &other)
  ~MString ()
MString operator+= (const MString &other)
MString operator+= (const char *other)
MString operator+= (double other)
MString operator+= (int other)
MString operator+= (unsigned int other)
MString operator+= (float other)
MString operator= (const MString &other)
MString operator= (const char *other)
MString operator= (double value)
bool  operator== (const MString &other) const
bool  operator== (const char *other) const
bool  operator!= (const MString &other) const
bool  operator!= (const char *other) const
MString  operator+ (const MString &other) const
MString  operator+ (const char *other) const
MString  operator+ (double value) const
MStatus  set (const char *charString)
MStatus  setUTF8 (const char *utf8String)
MStatus  setWChar (const wchar_t *wcharString)
MStatus  set (const char *charString, int charLength)
MStatus  setWChar (const wchar_t *wcharString, int wcharLength)
MStatus  set (double value)
MStatus  set (double value, int precision)
const char *  asChar () const
const char *  asChar (int &charLength) const
const char *  asUTF8 () const
const char *  asUTF8 (int &utf8Length) const
const wchar_t *  asWChar () const
const wchar_t *  asWChar (int &numChars) const
unsigned int  length () const
unsigned int  numChars () const
void  clear ()
int  index (char) const
int  indexW (char) const
int  indexW (wchar_t) const
int  indexW (const MString &) const
int  rindex (char) const
int  rindexW (char) const
int  rindexW (wchar_t) const
int  rindexW (const MString &) const
MStatus  split (char, MStringArray &) const
MStatus  split (wchar_t, MStringArray &) const
MString  substring (int start, int end) const
MString  substringW (int start, int end) const
MString toUpperCase ()
MString toLowerCase ()
bool  isShort () const
short  asShort () const
bool  isInt () const
int  asInt () const
bool  isUnsigned () const
unsigned int  asUnsigned () const
bool  isFloat () const
float  asFloat () const
bool  isDouble () const
double  asDouble () const
MString  expandEnvironmentVariablesAndTilde (MStatus *ReturnStatus=NULL) const
MString  expandFilePath (MStatus *ReturnStatus=NULL) const
MStatus  format (const MString &fmt, const MStringArray &args)
MStatus  format (const MString &fmt, const MString &arg1=MString::argUnused, const MString &arg2=MString::argUnused, const MString &arg3=MString::argUnused, const MString &arg4=MString::argUnused, const MString &arg5=MString::argUnused, const MString &arg6=MString::argUnused, const MString &arg7=MString::argUnused, const MString &arg8=MString::argUnused, const MString &arg9=MString::argUnused, const MString &arg10=MString::argUnused)

Friends

OPENMAYA_EXPORT std::ostream &  operator<< (std::ostream &, const MString &)
  NO SCRIPT SUPPORT.
OPENMAYA_EXPORT MString  operator+ (const char *, const MString &)
  NO SCRIPT SUPPORT.

Constructor & Destructor Documentation

MString::MString (  ) 

The Class constructor. Initializes the new MString instance to the empty string.

MString::MString ( const char *  charString  ) 

Class constructor. Create a new instance of an MString and initialize it to the given null-terminated character string.

NOTE: in multibyte locales, the character buffer encoding is assumed to be the native multibyte encoding of the current locale.

Parameters:
[in]  charString  the initial string value (null-terminated)

MString::MString ( const wchar_t *  wcharString  ) 

Class constructor. Create a new instance of an MString and initialize it with the null-terminated wide character string.

Parameters:
[in]  wcharString  the initial string value (null-terminated).

MString::MString ( const char *  charString,
int  charLength  
)

Class constructor. Create a new instance of an MString and initialize it with the character buffer passed, to the specified length. The length value is the length in bytes of the character buffer passed.

NOTE: in multibyte locales, the character buffer encoding is assumed to be the native multibyte encoding of the current locale.

Parameters:
[in]  charString  the initial string value.
[in]  charLength  the initial string length.

MString::MString ( const wchar_t *  wcharString,
int  wcharLength  
)

Class constructor. Create a new instance of an MString and initialize it to the given wide character string of specified length.

The length value corresponds to the number of wide characters in the initialization string.

Parameters:
[in]  wcharString  the initial string value.
[in]  wcharLength  the initial string length (number of characters).

MString::MString ( const MString other  ) 

Copy constructor. Create a new MString instance and initialize is with the same string as the given one.

Parameters:
[in]  other  the MString to copy from.

MString::~MString (  ) 

The class destructor.


Member Function Documentation

MString & MString::operator+= ( const MString other  ) 

Addition operator. The addition of two MStrings results in their concatenation.

MString & MString::operator+= ( const char *  other  ) 

Addition operator. The addition of an MString and the contents of a character buffer results in their concatenation.

NOTE: in multibyte locales, the character buffer encoding is assumed to be the native multibyte encoding of the current locale.

MString & MString::operator+= ( double  other  ) 

Addition operator. The addition of an MString and a double results in their concatenation.

MString & MString::operator+= ( int  other  ) 

Addition operator. The addition of an MString and an int results in their concatenation.

MString & MString::operator+= ( unsigned int  other  ) 

Addition operator. The addition of an MString and an unsigned int results in their concatenation.

MString & MString::operator+= ( float  other  ) 

Addition operator. The addition of an MString and a float results in their concatenation.

MString & MString::operator= ( const MString other  ) 

Assignment operator. Allows assignment between MString instances.

MString & MString::operator= ( const char *  other  ) 

Assignment operator. Allows assignment of the contents of a character buffer to this MString.

NOTE: in multibyte locales, the character buffer encoding is assumed to be the native multibyte encoding of the current locale.

MString & MString::operator= ( double  value  ) 

Assignment operator. Allows assignment of a number to this MString.

bool MString::operator== ( const MString other  )  const

Equality operator. Allows two MStrings to be compared to see if they contain identical strings.

bool MString::operator== ( const char *  other  )  const

Equality operator. Allows an MString and the contents of a character buffer to be compared to see if they contain identical strings.

NOTE: in multibyte locales, the character buffer encoding is assumed to be the native multibyte encoding of the current locale.

bool MString::operator!= ( const MString other  )  const

Inequality operator. Allows two MStrings to be compared to see if they differ.

bool MString::operator!= ( const char *  other  )  const

Inequality operator. Allows an MString to be compared with the contents of a character buffer to see if the two strings differ.

NOTE: in multibyte locales, the character buffer encoding is assumed to be the native multibyte encoding of the current locale.

MString MString::operator+ ( const MString other  )  const

Addition operator. The addition of two MStrings results in their concatenation.

MString MString::operator+ ( const char *  other  )  const

Addition operator. The addition of an MString and the contents of a character buffer results in their concatenation.

NOTE: in multibyte locales, the character buffer encoding is assumed to be the native multibyte encoding of the current locale.

MString MString::operator+ ( double  value  )  const

Addition operator. The addition of an MString and a number results in their concatenation.

MStatus MString::set ( const char *  charString  ) 

Set the value of the string in this MString instance. to the value of the null-terminated character string.

NOTE: in multibyte locales, the character buffer encoding is assumed to be the native multibyte encoding of the current locale.

Parameters:
[in]  charString  new string value (null-terminated).
Returns:
MS::kSuccess for success, otherwise MS::kFailure
Examples:

MStatus MString::setUTF8 ( const char *  utf8String  ) 

Set the value of the string in this MString instance using a null-terminated utf-8 encoded character string.

Note: conversion errors may occur if the multibyte encoding of the current locale cannot represent the utf-8 characters in the assignment string.

Parameters:
[in]  utf8String  null-terminated utf-8 character string buffer.
Returns:
MS::kSuccess for success, otherwise MS::kFailure

MStatus MString::setWChar ( const wchar_t *  wcharString  ) 

Set the value of the string in this MString instance using a null-terminated wide character string.

Parameters:
[in]  wcharString  null-terminated wide character string buffer.
Returns:
MS::kSuccess for success, otherwise MS::kFailure

MStatus MString::set ( const char *  charString,
int  charLength  
)

Set the value of the string in this MString instance to the value of the character buffer passed.

The length value is the length in bytes of the character buffer.

NOTE: in multibyte locales, the character buffer encoding is assumed to be the native multibyte encoding of the current locale.

Parameters:
[in]  charString  new string value.
[in]  charLength  new string length.
Returns:
MS::kSuccess for success, otherwise MS::kFailure

MStatus MString::setWChar ( const wchar_t *  wcharString,
int  wcharLength  
)

Set the value of the string in this MString instance using a wide string and its length.

The length value corresponds to the number of wide characters in the input string.

Parameters:
[in]  wcharString  New wide character string value.
[in]  wcharLength  New string length (number of wide characters)
Returns:
MS::kSuccess for success, otherwise MS::kFailure

MStatus MString::set ( double  value  ) 

Set the value of the string in this MString instance. The numeric value will be converted to a character string.

Parameters:
[in]  value  new number.
Returns:
MS::kSuccess for success, otherwise MS::kFailure

MStatus MString::set ( double  value,
int  precision  
)

Set the value of the string in this MString instance, with the given precision. The numeric value will be converted to a character string.

Parameters:
[in]  value  new number.
[in]  precision  the precision (number of decimal places).
Returns:
MS::kSuccess for success, otherwise MS::kFailure

const char * MString::asChar (  )  const

Return the current string in this MString instance as a C++ char* pointer. The string will be returned as a null-terminated buffer of type char.

In a localized environment, the string will contain a buffer of multibyte characters in the locale's native encoding.

The length of this representation of the string can be obtained by calling the alternate version of this method that returns the string length, or by calling MString::length().

NOTE: The string should be duplicated if it will be re-used.

Returns:
The char* pointer to the string in this MString instance.
Examples:

const char * MString::asChar ( int &  charLength  )  const

Return the current string in this MString instance as a C++ char* pointer. The string will be returned as a null-terminated buffer of type char.

In a localized environment, the string will contain a buffer of multibyte characters in the locale's native encoding.

The argument passed will be used to return the length of the character buffer returned in bytes (excluding the trailing null).

NOTE: the length value corresponds to the string's character length in bytes, which can differ from the number of characters in the string when running in a localized environment.

NOTE: The string should be duplicated if it will be re-used.

Parameters:
[out]  charLength  value which will be set to the length of the character buffer returned
Returns:
The char* pointer to the string in this MString instance.

const char * MString::asUTF8 (  )  const

Return the current string in this MString instance as a C++ char* pointer to a null-terminated utf-8 encoded string.

The length of this buffer can be obtained by calling the alternate form of MString::asUTF8 which returns the length value.

NOTE: The string should be duplicated if it will be re-used.

Returns:
The char* pointer to the utf-8 encoded string

const char * MString::asUTF8 ( int &  utf8Length  )  const

Return the current string in this MString instance as a C++ char* pointer to a null-terminated utf-8 encoded string. The integer argument passed will be used to return the length of this buffer (in bytes) excluding the trailing null.

NOTE: The string should be duplicated if it will be re-used.

Parameters:
[out]  utf8Length  Value which will be set to the length of the character buffer returned.
Returns:
The char* pointer to the utf-8 encoded string

const wchar_t * MString::asWChar (  )  const

Return the current string in this MString instance as pointer to a null terminated wide character (wchar_t) buffer. The number of characters in this buffer will be equivalent to MString::numChars, or can be determined by using the alternate form of MString::awWChar which returns the buffer length.

NOTE: wchar_t types are not portable between platforms and are not recommended for persistent data. A portable multibyte format such as UTF-8 is recommended for file I/O.

NOTE: The string should be duplicated if it will be re-used.

Returns:
The wchar_t* pointer to the string in this MString instance.

const wchar_t * MString::asWChar ( int &  wcharLength  )  const

Return the current string in this MString instance as pointer to a null terminated wide character (wchar_t) buffer.

The length value returned corresponds to the number of wide characters in the buffer returned (excluding the trailing null).

NOTE: wchar_t types are not portable between platforms and are not recommended for persistent data. A portable multibyte format such as UTF-8 is recommended for file I/O.

NOTE: The string should be duplicated if it will be re-used.

Parameters:
[out]  wcharLength  number of wide characters in buffer returned
Returns:
The wchar_t* pointer to the string in this MString instance.

unsigned int MString::length (  )  const

Returns the length of the string buffer in this MString instance.

This value corresponds to the length, in bytes, of the charcter buffer returned from the MString::asChar method, excluding the trailing null.

NOTE: When running in a localized (multibyte) environment, the MString::asChar method will return a multibyte buffer, in which the number of characters in the string may not correspond to the number of bytes in the multibyte representation. The use of the MString::numChars method is recommended in place of MString::length for determining the number of individual characters in the string.

Returns:
Unsigned integer value giving the string's character buffer length.
Examples:

unsigned int MString::numChars (  )  const

Returns the number of characters in the MString instance.

NOTE: this value corresponds to the number of actual characters in the string, not its character buffer length. It is suitable for localized environments as it correctly handles multibyte characters.

Returns:
Unsigned integer value giving the number of characters in the string.

void MString::clear (  ) 

Clears the contents of this MString instance and sets it value to the empty string.

Examples:

int MString::index ( char  searchChar  )  const

Returns the position of the first occurance of the character searchChar in the string or -1 if the character is not found.

The position value returned from index is a byte-based charcter position corresponding to the location in the asChar() form of the string.

NOTE: since this version of index works on the char form of the string it is not reliable within localized (multibyte) environments as the positions returned may not correctly match character boundaries in the multibyte buffer. Use of MString::indexW is recommended instead.

Parameters:
[in]  searchChar  the character to search for
Returns:
The position of searchChar in the string, or -1 if the searchChar is not found
Examples:

int MString::indexW ( char  searchChar  )  const

Returns the position of the first occurance of the character searchChar in the string or -1 if the character is not found.

The position value returned from indexW is a character-based position and correctly handles strings in localized (multibyte) environments. Use of MString::indexW over MString::index is recommended.

Parameters:
[in]  searchChar  the character to search for
Returns:
The position of searchChar in the string, or -1 if the searchChar is not found

int MString::indexW ( wchar_t  searchChar  )  const

Returns the position of the first occurance of the wide character searchChar in the string or -1 if the character is not found.

The position value returned from indexW is a character-based position and correctly handles strings in localized (multibyte) environments. Use of MString::indexW over MString::index is recommended.

Parameters:
[in]  searchChar  the wide character to search for
Returns:
The position of searchChar in the string, or -1 if the searchChar is not found

int MString::indexW ( const MString searchStr  )  const

Returns the position of the first occurance of the searchString in the string or -1 if it is not found.

The position value returned from indexW is a character-based position and correctly handles strings in localized (multibyte) environments.

Parameters:
[in]  searchStr  The string to search for.
Returns:
The starting position of searchString in the string, or -1 if it is not found

int MString::rindex ( char  searchChar  )  const

Returns the position of the last occurance of the character searchChar in the string or -1 if the character is not found.

The position value returned from rindex is a byte-based character position corresponding to the location in the asChar() form of the string.

NOTE: since this version of rindex works on the char form of the string it is not reliable within localized (multibyte) environments as the positions returned may not correctly match character boundaries in the multibyte buffer. Use of MString::rindexW is recommended instead.

Parameters:
[in]  searchChar  the character to search for
Returns:
The position of searchChar in the string, or -1 if the searchChar is not found
Examples:

int MString::rindexW ( char  searchChar  )  const

Returns the position of the last occurance of the character searchChar in the string or -1 if the character is not found.

The position value returned from rindexW is a character-based position and correctly handles strings in localized (multibyte) environments. Use of MString::indexW over MString::index is recommended.

Parameters:
[in]  searchChar  the character to search for
Returns:
The position of searchChar in the string, or -1 if the searchChar is not found

int MString::rindexW ( wchar_t  searchChar  )  const

Returns the position of the last occurance of the wide character searchChar in the string or -1 if the character is not found.

The position value returned from rindexW is a character-based position and correctly handles strings in localized (multibyte) environments. Use of MString::indexW over MString::index is recommended.

Parameters:
[in]  searchChar  the character to search for
Returns:
The position of searchChar in the string, or -1 if the searchChar is not found

int MString::rindexW ( const MString searchStr  )  const

Returns the position of the last occurance of the searchString in the string or -1 if it is not found.

The position value returned from indexW is a character-based position and correctly handles strings in localized (multibyte) environments.

Parameters:
[in]  searchStr  the string to search for
Returns:
The position of searchString in the string, or -1 if it is not found

MStatus MString::split ( char  theChar,
MStringArray theArray  
) const

Split the string up at each occurrence of theChar and place the separate strings into theArray. The current string instance is not modified.

NOTE: for compatibilty in localized environments an alternate form of of MString::split that accept wide-characters is also provided.

Parameters:
[in]  theChar  the character on which to split
[out]  theArray  the MStringArray to populate
Returns:
MS::kSuccess on success, and MS::kFailure on failure
Examples:

MStatus MString::split ( wchar_t  theWChar,
MStringArray theArray  
) const

Split the string up at each occurrence of the given wide character and place the separate strings into theArray. The current string instance is not modified.

NOTE: this method accepts a wide character type and is the preferred format for compatibility in localized environments.

Parameters:
[in]  theWChar  the character on which to split
[out]  theArray  the MStringArray to populate
Returns:
MS::kSuccess on success, and MS::kFailure on failure

MString MString::substring ( int  start,
int  end  
) const

Return a new MString instance that contains the characters from start to end inclusive.

Start and end are byte-based positions corresponding to the asChar() form of the string.

NOTE: since this version of substring works on the char form of the string it is not compatible with localized (multibyte) environments as the positions specified may not correctly match character boundaries in the multibyte buffer. Use of MString::substringW is recommended instead.

Parameters:
[in]  start  the index of the first character to copy
[in]  end  the index of the last character to copy
Returns:
An MString containing the substring.
Examples:

MString MString::substringW ( int  start,
int  end  
) const

Return a new MString instance that contains the characters from start to end inclusive.

Start and end are character-based positions and correctly deal with multibyte strings in localized environments.

NOTE: use of MString::substringW over MString::substring is recommended

Parameters:
[in]  start  the index of the first character to copy
[in]  end  the index of the last character to copy
Returns:
An MString containing the substring.

MString & MString::toUpperCase (  ) 

Modify the current instance of the string replacing all lower case characters in the corresponding upper case characters.

Returns:
A reference to the current, modified MString instance
Examples:

MString & MString::toLowerCase (  ) 

Modify the current instance of the string replacing all lower case characters in the corresponding upper case characters.

Returns:
A reference to the current, modified MString instance
Examples:

bool MString::isShort (  )  const

Returns true if the string represents a valid short, and false otherwise.

Returns:
True or false

short MString::asShort (  )  const

Returns the value of the string in this MString instance converted to a short. If the string does contain a valid string representation of a short, then the results of this operation are undefined.

Returns:
The value of the current string converted to a short.

bool MString::isInt (  )  const

Returns true if the string represents a valid int, and false otherwise.

Returns:
True or false

int MString::asInt (  )  const

Returns the value of the string in this MString instance converted to an integer. If the string does contain a valid string representation of an integer, then the results of this operation are undefined.

Returns:
The value of the current string converted to an integer.

bool MString::isUnsigned (  )  const

Returns true if the string represents a valid unsigned int, and false otherwise.

Returns:
True or false

unsigned int MString::asUnsigned (  )  const

Returns the value of the string in this MString instance converted to an unsigned integer. If the string does contain a valid string representation of an unsigned integer, then the results of this operation are undefined.

Returns:
The value of the current string converted to an integer.

bool MString::isFloat (  )  const

Returns true if the string represents a valid float, and false otherwise.

Returns:
True or false

float MString::asFloat (  )  const

Returns the value of the string in this MString instance converted to a float. If the string does contain a valid string representation of a float, then the results of this operation are undefined.

Returns:
The value of the current string converted to a float.

bool MString::isDouble (  )  const

Returns true if the string represents a valid double, and false otherwise.

Returns:
True or false
Examples:

double MString::asDouble (  )  const

Returns the value of the string in this MString instance converted to a double. If the string does contain a valid string representation of a double, then the results of this operation are undefined.

Returns:
The value of the current string converted to a double.

MString MString::expandEnvironmentVariablesAndTilde ( MStatus ReturnStatus = NULL  )  const

Returns a new string constructed by duplicating the current string with all environment variables expanded (and on UNIX, tilde characaters ("~") are also expanded. Environment variables may be of the form $ENV_VAR or ${ENV_VAR}. On Windows, ENV_VAR, ENV_VAR% and %{ENV_VAR}% are also accepted. If no environment variable in the system matches that given, the unexpanded variable is copied verbatim into the result string. On UNIX, any tilde characters ("~") will also be expanded according to the standard UNIX convention. If the user name associated with a tilde is undefined, the tilde and name which follows it are copied verbatim into the result string. Notes (1) when any error occurs, processing continues such that all subsequent environment variable and tilde occurences are processed and the resulting string can be displayed to the user to help diagnose the undefined entities (2) escape sequences using backslash characters are not supported.

Parameters:
[out]  ReturnStatus  status of the operation. MS::kSuccess for success, MS::kNotFound if one or more environment variables or tildes failed to expand.
Returns:
A new string containing the value of the original string with environment variable (and tilde characters on UNIX) which were defined expanded. All undefined environment variables and tildes are copied into the result string unexpanded.

MString MString::expandFilePath ( MStatus ReturnStatus = NULL  )  const

Returns a new string constructed by duplicating the current string with all environment variables expanded (and on UNIX, tilde characaters ("~") are also expanded. Environment variables may be of the form $ENV_VAR or ${ENV_VAR}. On Windows, ENV_VAR, ENV_VAR% and %{ENV_VAR}% are also accepted. If no environment variable in the system matches that given, the unexpanded variable is copied verbatim into the result string. On UNIX, any tilde characters ("~") will also be expanded according to the standard UNIX convention. If the user name associated with a tilde is undefined, the tilde and name which follows it are copied verbatim into the result string. Notes (1) when any error occurs, processing continues such that all subsequent environment variable and tilde occurences are processed and the resulting string can be displayed to the user to help diagnose the undefined entities (2) escape sequences using backslash characters are not supported.

This does some file-path specific expansion. So if we have an invalid sequence like $A;;$B or

A
:
B (on Mac/Linux), it will be collapsed to $A;$B or $A:$B respectively, then expanded.

We also do file-path specific nested environment variable expansion. So if you have $A/foo, and $A = "A;a", this will result in, A/foo;a/foo instead of A;a/foo. If you want A;a/foo, use MString::expandEnvironmentVariablesAndTilde

Parameters:
[out]  ReturnStatus  status of the operation. MS::kSuccess for success, MS::kNotFound if one or more environment variables or tildes failed to expand.
Returns:
A new string containing the value of the original string with environment variable (and tilde characters on UNIX) which were defined expanded. All undefined environment variables and tildes are copied into the result string unexpanded.

MStatus MString::format ( const MString fmt,
const MStringArray args  
)

Format the string value using a format specifier and an array of positional arguments.

A maximum of 10 arguments may be specified in the array passed. The number of arguments must match exactly the number of arguments expected by the format statement.

All arguments are passed as MStrings (any numeric data for example must already be formatted by the caller into an MString).

Format specifiers determine the relative position and ordering of arguments in the string using specifiers of the form: ^1s ^2s ^3s etc. See also the mel format command.

Parameters:
[in]  fmt  format string (up to 10 positional argument specifiers)
[in]  args  array of arguments to be positioned in the format string
Returns:
MS::kSuccess for success, otherwise MS::kFailure
Examples:

MStatus MString::format ( const MString fmt,
const MString arg1 = MString::argUnused,
const MString arg2 = MString::argUnused,
const MString arg3 = MString::argUnused,
const MString arg4 = MString::argUnused,
const MString arg5 = MString::argUnused,
const MString arg6 = MString::argUnused,
const MString arg7 = MString::argUnused,
const MString arg8 = MString::argUnused,
const MString arg9 = MString::argUnused,
const MString arg10 = MString::argUnused  
)

Format the string value using a format specifier and positional arguments.

A maximum of 10 argument strings may be passed in the argument list. This routine accepts a variable number of arguments in the argument list. Unused arguments should not be passed. (i.e. if 3 arguments are required by the format statement, exactly 3 arguments should be passed when calling MString::format).

All arguments are passed as MStrings (any numeric data for example must already be converted by the caller to an MString).

Format specifiers determine the relative position and ordering of arguments in the string using specifiers of the form: ^1s ^2s ^3s etc. See also the mel format command for more information.

Parameters:
[in]  fmt  format string (up to 10 positional arguments)
[in]  arg1  argument to be positioned in the format string
[in]  arg2  argument to be positioned in the format string
[in]  arg3  argument to be positioned in the format string
[in]  arg4  argument to be positioned in the format string
[in]  arg5  argument to be positioned in the format string
[in]  arg6  argument to be positioned in the format string
[in]  arg7  argument to be positioned in the format string
[in]  arg8  argument to be positioned in the format string
[in]  arg9  argument to be positioned in the format string
[in]  arg10  argument to be positioned in the format string
Returns:
MS::kSuccess for success, otherwise MS::kFailure

Friends And Related Function Documentation

OPENMAYA_EXPORT std::ostream& operator<< ( std::ostream &  s,
const MString str  
) [friend]

NO SCRIPT SUPPORT.

Print the contents of the given MString on the given ostream.

Parameters:
[in]  s  the ostream to print to
[in]  str  the MString whose value is to be printed
Returns:
The ostream reference, s, provided as the first parameter.

OPENMAYA_EXPORT MString operator+ ( const char *  first,
const MString second  
) [friend]

NO SCRIPT SUPPORT.

Addition operator. The addition of the contents of a character buffer and an MString results in their concatenation.

NOTE: in multibyte locales, the character buffer encoding is assumed to be the native multibyte encoding of the current locale.


Autodesk® Maya® 2011 © 1997-2010 Autodesk, Inc. All rights reserved. Generated with doxygen 1.5.6