LCOV - app.info - parser/html/nsHtml5Portability.cpp

LCOV - code coverage report
| Current view: | directory - parser/html - nsHtml5Portability.cpp (source / functions) |  | Found | Hit | Coverage |
| Test: | app.info | Lines: | 71 | 6 | 8.5 %
| Date: | 2012-07-07 | Functions: | 16 | 3 | 18.8 %

           1                 : /* ***** BEGIN LICENSE BLOCK *****
           2                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
           3                 :  *
           4                 :  * The contents of this file are subject to the Mozilla Public License Version
           5                 :  * 1.1 (the "License"); you may not use this file except in compliance with
           6                 :  * the License. You may obtain a copy of the License at
           7                 :  * http://www.mozilla.org/MPL/
           8                 :  *
           9                 :  * Software distributed under the License is distributed on an "AS IS" basis,
          10                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
          11                 :  * for the specific language governing rights and limitations under the
          12                 :  * License.
          13                 :  *
          14                 :  * The Original Code is HTML Parser C++ Translator code.
          15                 :  *
          16                 :  * The Initial Developer of the Original Code is
          17                 :  * Mozilla Foundation.
          18                 :  * Portions created by the Initial Developer are Copyright (C) 2008-2009
          19                 :  * the Initial Developer. All Rights Reserved.
          20                 :  *
          21                 :  * Contributor(s):
          22                 :  *   Henri Sivonen <hsivonen@iki.fi>
          23                 :  *
          24                 :  * Alternatively, the contents of this file may be used under the terms of
          25                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
          26                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
          27                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
          28                 :  * of those above. If you wish to allow use of your version of this file only
          29                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
          30                 :  * use your version of this file under the terms of the MPL, indicate your
          31                 :  * decision by deleting the provisions above and replace them with the notice
          32                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
          33                 :  * the provisions above, a recipient may use your version of this file under
          34                 :  * the terms of any one of the MPL, the GPL or the LGPL.
          35                 :  *
          36                 :  * ***** END LICENSE BLOCK ***** */
          37                 :
          38                 : #include "prtypes.h"
          39                 : #include "nsIAtom.h"
          40                 : #include "nsString.h"
          41                 : #include "jArray.h"
          42                 : #include "nsHtml5Portability.h"
          43                 :
          44                 : nsIAtom*
          45               0 : nsHtml5Portability::newLocalNameFromBuffer(PRUnichar* buf, PRInt32 offset, PRInt32 length, nsHtml5AtomTable* interner)
          46                 : {
          47               0 :   NS_ASSERTION(!offset, "The offset should always be zero here.");
          48               0 :   NS_ASSERTION(interner, "Didn't get an atom service.");
          49               0 :   return interner->GetAtom(nsDependentSubstring(buf, buf + length));
          50                 : }
          51                 :
          52                 : nsString*
          53               0 : nsHtml5Portability::newStringFromBuffer(PRUnichar* buf, PRInt32 offset, PRInt32 length)
          54                 : {
          55               0 :   return new nsString(buf + offset, length);
          56                 : }
          57                 :
          58                 : nsString*
          59               0 : nsHtml5Portability::newEmptyString()
          60                 : {
          61               0 :   return new nsString();
          62                 : }
          63                 :
          64                 : nsString*
          65               0 : nsHtml5Portability::newStringFromLiteral(const char* literal)
          66                 : {
          67               0 :   nsString* str = new nsString();
          68               0 :   str->AssignASCII(literal);
          69               0 :   return str;
          70                 : }
          71                 :
          72                 : nsString*
          73               0 : nsHtml5Portability::newStringFromString(nsString* string) {
          74               0 :   nsString* newStr = new nsString();
          75               0 :   newStr->Assign(*string);
          76               0 :   return newStr;
          77                 : }
          78                 :
          79                 : jArray<PRUnichar,PRInt32>
          80               0 : nsHtml5Portability::newCharArrayFromLocal(nsIAtom* local)
          81                 : {
          82               0 :   nsAutoString temp;
          83               0 :   local->ToString(temp);
          84               0 :   PRInt32 len = temp.Length();
          85               0 :   jArray<PRUnichar,PRInt32> arr = jArray<PRUnichar,PRInt32>::newJArray(len);
          86               0 :   memcpy(arr, temp.BeginReading(), len * sizeof(PRUnichar));
          87                 :   return arr;
          88                 : }
          89                 :
          90                 : jArray<PRUnichar,PRInt32>
          91               0 : nsHtml5Portability::newCharArrayFromString(nsString* string)
          92                 : {
          93               0 :   PRInt32 len = string->Length();
          94               0 :   jArray<PRUnichar,PRInt32> arr = jArray<PRUnichar,PRInt32>::newJArray(len);
          95               0 :   memcpy(arr, string->BeginReading(), len * sizeof(PRUnichar));
          96                 :   return arr;
          97                 : }
          98                 :
          99                 : nsIAtom*
         100               0 : nsHtml5Portability::newLocalFromLocal(nsIAtom* local, nsHtml5AtomTable* interner)
         101                 : {
         102               0 :   NS_PRECONDITION(local, "Atom was null.");
         103               0 :   NS_PRECONDITION(interner, "Atom table was null");
         104               0 :   if (!local->IsStaticAtom()) {
         105               0 :     nsAutoString str;
         106               0 :     local->ToString(str);
         107               0 :     local = interner->GetAtom(str);
         108                 :   }
         109               0 :   return local;
         110                 : }
         111                 :
         112                 : void
         113               0 : nsHtml5Portability::releaseString(nsString* str)
         114                 : {
         115               0 :   delete str;
         116               0 : }
         117                 :
         118                 : bool
         119             124 : nsHtml5Portability::localEqualsBuffer(nsIAtom* local, PRUnichar* buf, PRInt32 offset, PRInt32 length)
         120                 : {
         121             124 :   return local->Equals(nsDependentSubstring(buf + offset, buf + offset + length));
         122                 : }
         123                 :
         124                 : bool
         125               0 : nsHtml5Portability::lowerCaseLiteralIsPrefixOfIgnoreAsciiCaseString(const char* lowerCaseLiteral, nsString* string)
         126                 : {
         127               0 :   if (!string) {
         128               0 :     return false;
         129                 :   }
         130               0 :   const char* litPtr = lowerCaseLiteral;
         131               0 :   const PRUnichar* strPtr = string->BeginReading();
         132               0 :   const PRUnichar* end = string->EndReading();
         133                 :   PRUnichar litChar;
         134               0 :   while ((litChar = *litPtr)) {
         135               0 :     NS_ASSERTION(!(litChar >= 'A' && litChar <= 'Z'), "Literal isn't in lower case.");
         136               0 :     if (strPtr == end) {
         137               0 :       return false;
         138                 :     }
         139               0 :     PRUnichar strChar = *strPtr;
         140               0 :     if (strChar >= 'A' && strChar <= 'Z') {
         141               0 :       strChar += 0x20;
         142                 :     }
         143               0 :     if (litChar != strChar) {
         144               0 :       return false;
         145                 :     }
         146               0 :     ++litPtr;
         147               0 :     ++strPtr;
         148                 :   }
         149               0 :   return true;
         150                 : }
         151                 :
         152                 : bool
         153               0 : nsHtml5Portability::lowerCaseLiteralEqualsIgnoreAsciiCaseString(const char* lowerCaseLiteral, nsString* string)
         154                 : {
         155               0 :   if (!string) {
         156               0 :     return false;
         157                 :   }
         158               0 :   return string->LowerCaseEqualsASCII(lowerCaseLiteral);
         159                 : }
         160                 :
         161                 : bool
         162               0 : nsHtml5Portability::literalEqualsString(const char* literal, nsString* string)
         163                 : {
         164               0 :   if (!string) {
         165               0 :     return false;
         166                 :   }
         167               0 :   return string->EqualsASCII(literal);
         168                 : }
         169                 :
         170                 : bool
         171               0 : nsHtml5Portability::stringEqualsString(nsString* one, nsString* other)
         172                 : {
         173               0 :   return one->Equals(*other);
         174                 : }
         175                 :
         176                 : void
         177            1404 : nsHtml5Portability::initializeStatics()
         178                 : {
         179            1404 : }
         180                 :
         181                 : void
         182            1403 : nsHtml5Portability::releaseStatics()
         183                 : {
         184            1403 : }

Generated by: LCOV version 1.7