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


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

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


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

示例1:

void
RemoveBadFileNameCharacters(nsAString& aFileName,
                            PRBool     aAllPlatforms)
{
  // Get the list of bad characters.
  const char* badCharacters;
  if (aAllPlatforms)
    badCharacters = SB_FILE_BAD_CHARACTERS_ALL_PLATFORMS;
  else
    badCharacters = SB_FILE_BAD_CHARACTERS;

  // Remove all bad characters from the file name.
  aFileName.StripChars(badCharacters);

  // Windows does not like spaces at the begining or end of a file/folder name.
  // Windows also does not like dots at the begining or end of the file/folder
  // name and dots are bad as well on some other operating systems as they
  // represent a hidden file.
  aFileName.Trim(" .", PR_TRUE, PR_TRUE);
}
开发者ID:AntoineTurmel,项目名称:nightingale-hacking,代码行数:20,代码来源:sbFileUtils.cpp

示例2:

void
CompressWhitespace(nsAString& aString)
{
  aString.Trim(" \n\t\r");

  PRUnichar *start;
  PRUint32 len = NS_StringGetMutableData(aString, PR_UINT32_MAX, &start);
  PRUnichar *end = start + len;

  for (PRUnichar *cur = start; cur < end; ++cur) {
    if (!NS_IsAsciiWhitespace(*cur))
      continue;

    *cur = ' ';

    PRUnichar *wend;
    for (wend = cur + 1; wend < end && NS_IsAsciiWhitespace(*wend); ++wend) {
      // nothing to do but loop
    }

    if (wend == cur + 1)
      continue;

    PRUint32 wlen = wend - cur - 1;

    // fix "end"
    end -= wlen;

    // move everything forwards a bit
    for (PRUnichar *m = cur + 1; m < end; ++m) {
      *m = *(m + wlen);
    }
  }

  // re-terminate
  *end = '\0';

  // Set the new length.
  aString.SetLength(end - start);
}
开发者ID:fortunto2,项目名称:celtx,代码行数:40,代码来源:nsStringAPI.cpp

示例3: sbWinCreateDeviceFile

nsresult
sbWinGetSCSIProductInfo(DEVINST    aDevInst,
                        nsAString& aVendorID,
                        nsAString& aProductID)
{
  DWORD    byteCount;
  BOOL     success;
  errno_t  errno;
  nsresult rv;

  // Create a disk interface device file.
  sbAutoHANDLE diskHandle;
  GUID         guid = GUID_DEVINTERFACE_DISK;
  rv = sbWinCreateDeviceFile(diskHandle.StartAssignment(),
                             aDevInst,
                             &guid,
                             0,
                             FILE_SHARE_READ | FILE_SHARE_WRITE,
                             NULL,
                             OPEN_EXISTING,
                             0,
                             NULL);
  NS_ENSURE_SUCCESS(rv, rv);

  // Set up a storage property query to get the storage device descriptor.
  STORAGE_PROPERTY_QUERY storagePropertyQuery;
  memset(&storagePropertyQuery, 0, sizeof(storagePropertyQuery));
  storagePropertyQuery.PropertyId = StorageDeviceProperty;
  storagePropertyQuery.QueryType = PropertyStandardQuery;

  // Determine how many bytes are required to hold the full storage device
  // descriptor.
  STORAGE_DESCRIPTOR_HEADER storageDescriptorHeader;
  success = DeviceIoControl(diskHandle,
                            IOCTL_STORAGE_QUERY_PROPERTY,
                            &storagePropertyQuery,
                            sizeof(storagePropertyQuery),
                            &storageDescriptorHeader,
                            sizeof(storageDescriptorHeader),
                            &byteCount,
                            NULL);
  NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
  NS_ENSURE_TRUE(byteCount == sizeof(storageDescriptorHeader),
                 NS_ERROR_FAILURE);

  // Allocate the storage device descriptor.
  sbAutoMemPtr<STORAGE_DEVICE_DESCRIPTOR>
    storageDeviceDescriptor = static_cast<PSTORAGE_DEVICE_DESCRIPTOR>
                                (malloc(storageDescriptorHeader.Size));
  NS_ENSURE_TRUE(storageDeviceDescriptor, NS_ERROR_OUT_OF_MEMORY);

  // Get the storage device descriptor.
  success = DeviceIoControl(diskHandle,
                            IOCTL_STORAGE_QUERY_PROPERTY,
                            &storagePropertyQuery,
                            sizeof(storagePropertyQuery),
                            storageDeviceDescriptor,
                            storageDescriptorHeader.Size,
                            &byteCount,
                            NULL);
  NS_ENSURE_TRUE(success, NS_ERROR_FAILURE);
  NS_ENSURE_TRUE(byteCount == storageDescriptorHeader.Size, NS_ERROR_FAILURE);

  // Return results with trailing spaces trimmed.  SCSI inquiry vendor and
  // product IDs have trailing spaces as filler.
  aVendorID.AssignLiteral
              (reinterpret_cast<char*>(storageDeviceDescriptor.get()) +
               storageDeviceDescriptor->VendorIdOffset);
  aVendorID.Trim(" ", PR_FALSE, PR_TRUE);
  aProductID.AssignLiteral
               (reinterpret_cast<char*>(storageDeviceDescriptor.get()) +
                storageDeviceDescriptor->ProductIdOffset);
  aProductID.Trim(" ", PR_FALSE, PR_TRUE);

  return NS_OK;
}
开发者ID:AntoineTurmel,项目名称:nightingale-hacking,代码行数:76,代码来源:sbWindowsStorageDeviceUtils.cpp


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