2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1998-12-24 05:07:14 +00:00
|
|
|
|
1999-01-05 21:22:20 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
Implementations for a bunch of useful RDF utility routines. Many of
|
|
|
|
these will eventually be exported outside of RDF.DLL via the
|
|
|
|
nsIRDFService interface.
|
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
TO DO
|
|
|
|
|
|
|
|
1) Make this so that it doesn't permanently leak the RDF service
|
|
|
|
object.
|
|
|
|
|
|
|
|
2) Make container functions thread-safe. They currently don't ensure
|
|
|
|
that the RDF:nextVal property is maintained safely.
|
|
|
|
|
1999-01-05 21:22:20 +00:00
|
|
|
*/
|
|
|
|
|
1999-02-16 19:30:04 +00:00
|
|
|
#include "nsCOMPtr.h"
|
1999-01-20 01:42:13 +00:00
|
|
|
#include "nsIRDFDataSource.h"
|
1998-12-24 05:07:14 +00:00
|
|
|
#include "nsIRDFNode.h"
|
1999-01-05 03:53:15 +00:00
|
|
|
#include "nsIRDFService.h"
|
1999-01-12 19:41:06 +00:00
|
|
|
#include "nsIServiceManager.h"
|
1999-06-09 08:29:51 +00:00
|
|
|
#include "nsIURL.h"
|
1999-06-18 17:34:08 +00:00
|
|
|
#include "nsIIOService.h"
|
1999-06-23 03:29:44 +00:00
|
|
|
#include "nsIURL.h"
|
2001-04-10 06:01:08 +00:00
|
|
|
#include "nsNetUtil.h"
|
1999-01-12 19:41:06 +00:00
|
|
|
#include "nsRDFCID.h"
|
1998-12-24 05:07:14 +00:00
|
|
|
#include "nsString.h"
|
1999-03-29 19:52:54 +00:00
|
|
|
#include "nsXPIDLString.h"
|
2001-10-13 00:16:32 +00:00
|
|
|
#include "nsUnicharUtils.h"
|
1998-12-24 05:07:14 +00:00
|
|
|
#include "rdfutil.h"
|
|
|
|
|
1999-01-12 19:41:06 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1999-06-16 04:45:36 +00:00
|
|
|
nsresult
|
2004-09-09 20:17:36 +00:00
|
|
|
rdf_MakeRelativeRef(const nsCSubstring& aBaseURI, nsCString& aURI)
|
1999-01-22 06:48:25 +00:00
|
|
|
{
|
1999-06-09 08:29:51 +00:00
|
|
|
// This implementation is extremely simple: e.g., it can't compute
|
|
|
|
// relative paths, or anything fancy like that. If the context URI
|
|
|
|
// is not a prefix of the URI in question, we'll just bail.
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t prefixLen = aBaseURI.Length();
|
2003-07-14 07:37:39 +00:00
|
|
|
if (prefixLen != 0 && StringBeginsWith(aURI, aBaseURI)) {
|
2002-01-25 22:28:55 +00:00
|
|
|
if (prefixLen < aURI.Length() && aURI.CharAt(prefixLen) == '/')
|
|
|
|
++prefixLen; // chop the leading slash so it's not `absolute'
|
1999-01-22 06:48:25 +00:00
|
|
|
|
2002-01-25 22:28:55 +00:00
|
|
|
aURI.Cut(0, prefixLen);
|
|
|
|
}
|
1999-02-17 11:09:57 +00:00
|
|
|
|
1999-06-09 08:29:51 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-01-15 01:56:15 +00:00
|
|
|
void
|
|
|
|
rdf_FormatDate(PRTime aTime, nsACString &aResult)
|
|
|
|
{
|
|
|
|
// Outputs Unixish date in GMT plus usecs; e.g.,
|
2008-01-29 12:18:35 +00:00
|
|
|
// Wed Jan 9 19:15:13 2002 +002441
|
2002-01-15 01:56:15 +00:00
|
|
|
//
|
|
|
|
PRExplodedTime t;
|
2008-01-29 12:18:35 +00:00
|
|
|
PR_ExplodeTime(aTime, PR_GMTParameters, &t);
|
2002-01-15 01:56:15 +00:00
|
|
|
|
2002-11-12 02:12:02 +00:00
|
|
|
char buf[256];
|
2008-01-29 12:18:35 +00:00
|
|
|
PR_FormatTimeUSEnglish(buf, sizeof buf, "%a %b %d %H:%M:%S %Y", &t);
|
2002-01-15 01:56:15 +00:00
|
|
|
aResult.Append(buf);
|
|
|
|
|
|
|
|
// usecs
|
2014-05-22 03:48:51 +00:00
|
|
|
aResult.AppendLiteral(" +");
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t usec = t.tm_usec;
|
|
|
|
for (int32_t digit = 100000; digit > 1; digit /= 10) {
|
2002-01-15 01:56:15 +00:00
|
|
|
aResult.Append(char('0' + (usec / digit)));
|
|
|
|
usec %= digit;
|
|
|
|
}
|
|
|
|
aResult.Append(char('0' + usec));
|
|
|
|
}
|
|
|
|
|
|
|
|
PRTime
|
|
|
|
rdf_ParseDate(const nsACString &aTime)
|
|
|
|
{
|
|
|
|
PRTime t;
|
2011-10-17 14:59:28 +00:00
|
|
|
PR_ParseTimeString(PromiseFlatCString(aTime).get(), true, &t);
|
2002-01-15 01:56:15 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t usec = 0;
|
2002-01-15 01:56:15 +00:00
|
|
|
|
|
|
|
nsACString::const_iterator begin, digit, end;
|
|
|
|
aTime.BeginReading(begin);
|
|
|
|
aTime.EndReading(end);
|
|
|
|
|
|
|
|
// Walk backwards until we find a `+', run out of string, or a
|
|
|
|
// non-numeric character.
|
|
|
|
digit = end;
|
|
|
|
while (--digit != begin && *digit != '+') {
|
|
|
|
if (*digit < '0' || *digit > '9')
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (digit != begin && *digit == '+') {
|
|
|
|
// There's a usec field specified (or, at least, something
|
|
|
|
// that looks close enough. Parse it, and add it to the time.
|
|
|
|
while (++digit != end) {
|
|
|
|
usec *= 10;
|
|
|
|
usec += *digit - '0';
|
|
|
|
}
|
|
|
|
|
2013-07-18 20:47:55 +00:00
|
|
|
t += usec;
|
2002-01-15 01:56:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return t;
|
|
|
|
}
|