当前位置: 首页>>代码示例>>C++>>正文


C++ nsString::Trim方法代码示例

本文整理汇总了C++中nsString::Trim方法的典型用法代码示例。如果您正苦于以下问题:C++ nsString::Trim方法的具体用法?C++ nsString::Trim怎么用?C++ nsString::Trim使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nsString的用法示例。


在下文中一共展示了nsString::Trim方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CleanupHandlerPath

// Strip a handler command string of its quotes and parameters.
static void CleanupHandlerPath(nsString& aPath)
{
  // Example command strings passed into this routine:

  // 1) C:\Program Files\Company\some.exe -foo -bar
  // 2) C:\Program Files\Company\some.dll
  // 3) C:\Windows\some.dll,-foo -bar
  // 4) C:\Windows\some.cpl,-foo -bar

  int32_t lastCommaPos = aPath.RFindChar(',');
  if (lastCommaPos != kNotFound)
    aPath.Truncate(lastCommaPos);

  aPath.Append(' ');

  // case insensitive
  uint32_t index = aPath.Find(".exe ", true);
  if (index == kNotFound)
    index = aPath.Find(".dll ", true);
  if (index == kNotFound)
    index = aPath.Find(".cpl ", true);

  if (index != kNotFound)
    aPath.Truncate(index + 4);
  aPath.Trim(" ", true, true);
}
开发者ID:Andrel322,项目名称:gecko-dev,代码行数:27,代码来源:nsOSHelperAppService.cpp

示例2: ExtractCharset

void nsEudoraCompose::ExtractCharset(nsString& str)
{
  int32_t idx = MsgFind(str, "charset=", true, 0);
  if (idx != -1) {
    str.Cut(0, idx + 8);
    idx = str.FindChar(';');
    if (idx != -1)
      str.SetLength(idx);
    str.Trim(kWhitespace);
    if ((str.CharAt(0) == '"') && (str.Length() > 2)) {
      str.SetLength(str.Length() - 1);
      str.Cut(0, 1);
      str.Trim(kWhitespace);
    }
  }
  else
    str.Truncate();
}
开发者ID:bolt-dev,项目名称:comm,代码行数:18,代码来源:nsEudoraCompose.cpp

示例3: GetValueString

// If the value is a string, get it...
void CWAB::GetValueString( LPSPropValue pVal, nsString& val)
{
  val.Truncate();

  if (!pVal)
    return;

    switch( PROP_TYPE( pVal->ulPropTag)) {
  case PT_STRING8: {
      CStrToUnicode( (const char *) (pVal->Value.lpszA), val);
    }
        break;
    case PT_UNICODE:
      val = (PRUnichar *) (pVal->Value.lpszW);
    break;
    case PT_MV_STRING8: {
      nsString  tmp;
            ULONG  j;
            for(j = 0; j < pVal->Value.MVszA.cValues; j++) {
        CStrToUnicode( (const char *) (pVal->Value.MVszA.lppszA[j]), tmp);
                val += tmp;
                val.Append(NS_ConvertASCIItoUTF16(TR_OUTPUT_EOL));
            }
        }
        break;
    case PT_MV_UNICODE: {
            ULONG  j;
            for(j = 0; j < pVal->Value.MVszW.cValues; j++) {
                val += (PRUnichar *) (pVal->Value.MVszW.lppszW[j]);
                val.Append(NS_ConvertASCIItoUTF16(TR_OUTPUT_EOL));
            }
        }
        break;

    case PT_I2:
    case PT_LONG:
    case PT_R4:
    case PT_DOUBLE:
    case PT_BOOLEAN: {
      /*
      TCHAR sz[256];
            wsprintf(sz,"%d", pVal->Value.l);
            val = sz;
      */
        }
        break;

    case PT_BINARY:
    break;

    default:
        break;
    }

  val.Trim( kWhitespace, PR_TRUE, PR_TRUE);
}
开发者ID:binoc-software,项目名称:mozilla-cvs,代码行数:57,代码来源:WabObject.cpp

示例4: ExtractType

void nsEudoraCompose::ExtractType(nsString& str)
{
  nsString tStr;
  int32_t idx = str.FindChar(';');
  if (idx != -1)
    str.SetLength(idx);

  str.Trim(kWhitespace);

  if ((str.CharAt(0) == '"') && (str.Length() > 2)) {
    str.SetLength(str.Length() - 1);
    str.Cut(0, 1);
    str.Trim(kWhitespace);
  }

  // if multipart then ignore it since no outlook message body is ever
  // valid multipart!
  if (StringBeginsWith(str, NS_LITERAL_STRING("multipart/"), nsCaseInsensitiveStringComparator()))
    str.Truncate();
}
开发者ID:bolt-dev,项目名称:comm,代码行数:20,代码来源:nsEudoraCompose.cpp

示例5: ExtractCharset

void nsEudoraCompose::ExtractCharset( nsString& str)
{
  nsString tStr;
  PRInt32 idx = str.Find( "charset=", PR_TRUE);
  if (idx != -1) {
    idx += 8;
    str.Right( tStr, str.Length() - idx);
    idx = tStr.FindChar( ';');
    if (idx != -1)
      tStr.Left( str, idx);
    else
      str = tStr;
    str.Trim( kWhitespace);
    if ((str.CharAt( 0) == '"') && (str.Length() > 2)) {
      str.Mid( tStr, 1, str.Length() - 2);
      str = tStr;
      str.Trim( kWhitespace);
    }
  }
  else
    str.Truncate();
}
开发者ID:binoc-software,项目名称:mozilla-cvs,代码行数:22,代码来源:nsEudoraCompose.cpp

示例6: ExtractType

void nsEudoraCompose::ExtractType( nsString& str)
{
  nsString tStr;
  PRInt32 idx = str.FindChar( ';');
  if (idx != -1) {
    str.Left( tStr, idx);
    str = tStr;
  }
  str.Trim( kWhitespace);

  if ((str.CharAt( 0) == '"') && (str.Length() > 2)) {
    str.Mid( tStr, 1, str.Length() - 2);
    str = tStr;
    str.Trim( kWhitespace);
  }

  // if multipart then ignore it since no outlook message body is ever
  // valid multipart!
  if (str.Length() > 10) {
    str.Left( tStr, 10);
    if (tStr.LowerCaseEqualsLiteral("multipart/"))
      str.Truncate();
  }
}
开发者ID:binoc-software,项目名称:mozilla-cvs,代码行数:24,代码来源:nsEudoraCompose.cpp

示例7: switch

// static
void
nsTextEditRules::HandleNewLines(nsString &aString,
                                PRInt32 aNewlineHandling)
{
  if (aNewlineHandling < 0) {
    PRInt32 caretStyle;
    nsPlaintextEditor::GetDefaultEditorPrefs(aNewlineHandling, caretStyle);
  }

  switch(aNewlineHandling)
  {
  case nsIPlaintextEditor::eNewlinesReplaceWithSpaces:
    // Strip trailing newlines first so we don't wind up with trailing spaces
    aString.Trim(CRLF, false, true);
    aString.ReplaceChar(CRLF, ' ');
    break;
  case nsIPlaintextEditor::eNewlinesStrip:
    aString.StripChars(CRLF);
    break;
  case nsIPlaintextEditor::eNewlinesPasteToFirst:
  default:
    {
      PRInt32 firstCRLF = aString.FindCharInSet(CRLF);

      // we get first *non-empty* line.
      PRInt32 offset = 0;
      while (firstCRLF == offset)
      {
        offset++;
        firstCRLF = aString.FindCharInSet(CRLF, offset);
      }
      if (firstCRLF > 0)
        aString.Truncate(firstCRLF);
      if (offset > 0)
        aString.Cut(0, offset);
    }
    break;
  case nsIPlaintextEditor::eNewlinesReplaceWithCommas:
    aString.Trim(CRLF, true, true);
    aString.ReplaceChar(CRLF, ',');
    break;
  case nsIPlaintextEditor::eNewlinesStripSurroundingWhitespace:
    {
      // find each newline, and strip all the whitespace before
      // and after it
      PRInt32 firstCRLF = aString.FindCharInSet(CRLF);
      while (firstCRLF >= 0)
      {
        PRUint32 wsBegin = firstCRLF, wsEnd = firstCRLF + 1;
        // look backwards for the first non-whitespace char
        while (wsBegin > 0 && NS_IS_SPACE(aString[wsBegin - 1]))
          --wsBegin;
        while (wsEnd < aString.Length() && NS_IS_SPACE(aString[wsEnd]))
          ++wsEnd;
        // now cut this range out of the string
        aString.Cut(wsBegin, wsEnd - wsBegin);
        // look for another CR or LF
        firstCRLF = aString.FindCharInSet(CRLF);
      }
    }
    break;
  case nsIPlaintextEditor::eNewlinesPasteIntact:
    // even if we're pasting newlines, don't paste leading/trailing ones
    aString.Trim(CRLF, true, true);
    break;
  }
}
开发者ID:CervantesYu,项目名称:mozilla-central,代码行数:68,代码来源:nsTextEditRules.cpp

示例8: switch

// static
void
nsTextEditRules::HandleNewLines(nsString &aString,
                                int32_t aNewlineHandling)
{
  if (aNewlineHandling < 0) {
    int32_t caretStyle;
    nsPlaintextEditor::GetDefaultEditorPrefs(aNewlineHandling, caretStyle);
  }

  switch(aNewlineHandling)
  {
  case nsIPlaintextEditor::eNewlinesReplaceWithSpaces:
    // Strip trailing newlines first so we don't wind up with trailing spaces
    aString.Trim(CRLF, false, true);
    aString.ReplaceChar(CRLF, ' ');
    break;
  case nsIPlaintextEditor::eNewlinesStrip:
    aString.StripChars(CRLF);
    break;
  case nsIPlaintextEditor::eNewlinesPasteToFirst:
  default:
    {
      int32_t firstCRLF = aString.FindCharInSet(CRLF);

      // we get first *non-empty* line.
      int32_t offset = 0;
      while (firstCRLF == offset)
      {
        offset++;
        firstCRLF = aString.FindCharInSet(CRLF, offset);
      }
      if (firstCRLF > 0)
        aString.Truncate(firstCRLF);
      if (offset > 0)
        aString.Cut(0, offset);
    }
    break;
  case nsIPlaintextEditor::eNewlinesReplaceWithCommas:
    aString.Trim(CRLF, true, true);
    aString.ReplaceChar(CRLF, ',');
    break;
  case nsIPlaintextEditor::eNewlinesStripSurroundingWhitespace:
    {
      nsString result;
      uint32_t offset = 0;
      while (offset < aString.Length())
      {
        int32_t nextCRLF = aString.FindCharInSet(CRLF, offset);
        if (nextCRLF < 0) {
          result.Append(nsDependentSubstring(aString, offset));
          break;
        }
        uint32_t wsBegin = nextCRLF;
        // look backwards for the first non-whitespace char
        while (wsBegin > offset && NS_IS_SPACE(aString[wsBegin - 1]))
          --wsBegin;
        result.Append(nsDependentSubstring(aString, offset, wsBegin - offset));
        offset = nextCRLF + 1;
        while (offset < aString.Length() && NS_IS_SPACE(aString[offset]))
          ++offset;
      }
      aString = result;
    }
    break;
  case nsIPlaintextEditor::eNewlinesPasteIntact:
    // even if we're pasting newlines, don't paste leading/trailing ones
    aString.Trim(CRLF, true, true);
    break;
  }
}
开发者ID:Wrichik1999,项目名称:gecko-dev,代码行数:71,代码来源:nsTextEditRules.cpp

示例9: GetField

bool nsTextAddress::GetField(const nsAString &aLine, int32_t index,
                             nsString &field, char16_t delim) {
  bool result = false;
  int32_t pos = 0;
  int32_t maxLen = aLine.Length();
  char16_t tab = char16_t('\t');
  char16_t doubleQuote = char16_t('"');

  field.Truncate();

  if (delim == tab) tab = 0;

  while (index && (pos < maxLen)) {
    while (((aLine[pos] == char16_t(' ')) || (aLine[pos] == tab)) &&
           (pos < maxLen)) {
      pos++;
    }
    if (pos >= maxLen) break;
    if (aLine[pos] == doubleQuote) {
      do {
        pos++;
        if (((pos + 1) < maxLen) && (aLine[pos] == doubleQuote) &&
            (aLine[pos + 1] == doubleQuote)) {
          pos += 2;
        }
      } while ((pos < maxLen) && (aLine[pos] != doubleQuote));
      if (pos < maxLen) pos++;
    }
    if (pos >= maxLen) break;

    while ((pos < maxLen) && (aLine[pos] != delim)) pos++;

    if (pos >= maxLen) break;

    index--;
    pos++;
  }

  if (pos >= maxLen) return result;

  result = true;

  while ((pos < maxLen) && ((aLine[pos] == ' ') || (aLine[pos] == tab))) pos++;

  int32_t fLen = 0;
  int32_t startPos = pos;
  bool quoted = false;
  if (aLine[pos] == '"') {
    startPos++;
    fLen = -1;
    do {
      pos++;
      fLen++;
      if (((pos + 1) < maxLen) && (aLine[pos] == doubleQuote) &&
          (aLine[pos + 1] == doubleQuote)) {
        quoted = true;
        pos += 2;
        fLen += 2;
      }
    } while ((pos < maxLen) && (aLine[pos] != doubleQuote));
  } else {
    while ((pos < maxLen) && (aLine[pos] != delim)) {
      pos++;
      fLen++;
    }
  }

  if (!fLen) {
    return result;
  }

  field.Append(nsDependentSubstring(aLine, startPos, fLen));
  field.Trim(kWhitespace);

  if (quoted) {
    int32_t offset = field.Find("\"\"");
    while (offset != -1) {
      field.Cut(offset, 1);
      offset = MsgFind(field, "\"\"", false, offset + 1);
    }
  }

  return result;
}
开发者ID:mozilla,项目名称:releases-comm-central,代码行数:84,代码来源:nsTextAddress.cpp


注:本文中的nsString::Trim方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。