本文整理汇总了C++中nsString::AssignASCII方法的典型用法代码示例。如果您正苦于以下问题:C++ nsString::AssignASCII方法的具体用法?C++ nsString::AssignASCII怎么用?C++ nsString::AssignASCII使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsString
的用法示例。
在下文中一共展示了nsString::AssignASCII方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RandomCookie
/** Returns a string containing a 11-digit random cookie based upon the
* current local time and the elapsed execution of the program.
* @param aCookie returned cookie string
* @return NS_OK on success
*/
NS_IMETHODIMP mozXMLTermUtils::RandomCookie(nsString& aCookie)
{
// Current local time
PRExplodedTime localTime;
PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &localTime);
PRInt32 randomNumberA = localTime.tm_sec*1000000+localTime.tm_usec;
PRIntervalTime randomNumberB = PR_IntervalNow();
XMLT_LOG(mozXMLTermUtils::RandomCookie,30,("ranA=0x%x, ranB=0x%x\n",
randomNumberA, randomNumberB));
PR_ASSERT(randomNumberA >= 0);
PR_ASSERT(randomNumberB >= 0);
static const char cookieDigits[17] = "0123456789abcdef";
char cookie[12];
int j;
for (j=0; j<6; j++) {
cookie[j] = cookieDigits[randomNumberA%16];
randomNumberA = randomNumberA/16;
}
for (j=6; j<11; j++) {
cookie[j] = cookieDigits[randomNumberB%16];
randomNumberB = randomNumberB/16;
}
cookie[11] = '\0';
aCookie.AssignASCII(cookie);
return NS_OK;
}
示例2: sizeof
NS_IMETHODIMP
nsInstallVersion::ToString(nsString& aReturn)
{
char buf[128];
PRUint32 len;
len=PR_snprintf(buf, sizeof(buf), "%d.%d.%d.%d", mMajor, mMinor, mRelease, mBuild);
aReturn.AssignASCII(buf,len);
return NS_OK;
}
示例3: TimeStamp
/** Returns a timestamp string containing the local time, if at least
* deltaSec seconds have elapsed since the last timestamp. Otherwise,
* a null string is returned.
* @param deltaSec minimum elapsed seconds since last timestamp (>=0)
* @param lastTime in/out parameter containing time of last timestamp
* @param aTimeStamp returned timestamp string
* @return NS_OK on success
*/
NS_IMETHODIMP mozXMLTermUtils::TimeStamp(PRInt32 deltaSec, PRTime& lastTime,
nsString& aTimeStamp)
{
static const PRInt32 DATE_LEN = 19;
PRTime deltaTime ;
char dateStr[DATE_LEN+1];
PRTime curTime, difTime;
curTime = PR_Now();
LL_SUB(difTime, curTime, lastTime);
LL_I2L(deltaTime, deltaSec*1000000);
if (LL_CMP(difTime, <, deltaTime)) {
// Not enough time has elapsed for a new time stamp
aTimeStamp.SetLength(0);
return NS_OK;
}
lastTime = curTime;
// Current local time
PRExplodedTime localTime;
PR_ExplodeTime(curTime, PR_LocalTimeParameters, &localTime);
PRInt32 nWritten = PR_snprintf(dateStr, DATE_LEN+1,
"%02d:%02d:%02d %02d/%02d/%04d", // XXX i18n!
localTime.tm_hour, localTime.tm_min, localTime.tm_sec,
localTime.tm_mday, localTime.tm_month+1, localTime.tm_year);
if (nWritten != DATE_LEN)
return NS_ERROR_FAILURE;
XMLT_LOG(mozXMLTermUtils::LocalTime,99,("localTime=%s\n", dateStr));
aTimeStamp.AssignASCII(dateStr);
return NS_OK;
}