LCOV - code coverage report
Current view: directory - parser/htmlparser/src - nsParserService.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 45 21 46.7 %
Date: 2012-06-02 Functions: 16 10 62.5 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
       2                 :  *
       3                 :  * ***** BEGIN LICENSE BLOCK *****
       4                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       5                 :  *
       6                 :  * The contents of this file are subject to the Mozilla Public License Version
       7                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       8                 :  * the License. You may obtain a copy of the License at
       9                 :  * http://www.mozilla.org/MPL/
      10                 :  *
      11                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      12                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      13                 :  * for the specific language governing rights and limitations under the
      14                 :  * License.
      15                 :  *
      16                 :  * The Original Code is Mozilla Communicator client code.
      17                 :  *
      18                 :  * The Initial Developer of the Original Code is
      19                 :  * Netscape Communications Corporation.
      20                 :  * Portions created by the Initial Developer are Copyright (C) 1998
      21                 :  * the Initial Developer. All Rights Reserved.
      22                 :  *
      23                 :  * Contributor(s):
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      27                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 : #include "nsDOMError.h"
      40                 : #include "nsIAtom.h"
      41                 : #include "nsParserService.h"
      42                 : #include "nsHTMLEntities.h"
      43                 : #include "nsElementTable.h"
      44                 : #include "nsICategoryManager.h"
      45                 : #include "nsCategoryManagerUtils.h"
      46                 : 
      47                 : extern "C" int MOZ_XMLCheckQName(const char* ptr, const char* end,
      48                 :                                  int ns_aware, const char** colon);
      49                 : 
      50              36 : nsParserService::nsParserService()
      51                 : {
      52              36 : }
      53                 : 
      54              72 : nsParserService::~nsParserService()
      55                 : {
      56             144 : }
      57                 : 
      58             324 : NS_IMPL_ISUPPORTS1(nsParserService, nsIParserService)
      59                 : 
      60                 : PRInt32
      61               0 : nsParserService::HTMLAtomTagToId(nsIAtom* aAtom) const
      62                 : {
      63               0 :   return nsHTMLTags::LookupTag(nsDependentAtomString(aAtom));
      64                 : }
      65                 : 
      66                 : PRInt32
      67             801 : nsParserService::HTMLCaseSensitiveAtomTagToId(nsIAtom* aAtom) const
      68                 : {
      69             801 :   return nsHTMLTags::CaseSensitiveLookupTag(aAtom);
      70                 : }
      71                 : 
      72                 : PRInt32
      73               0 : nsParserService::HTMLStringTagToId(const nsAString& aTag) const
      74                 : {
      75               0 :   return nsHTMLTags::LookupTag(aTag);
      76                 : }
      77                 : 
      78                 : const PRUnichar*
      79               0 : nsParserService::HTMLIdToStringTag(PRInt32 aId) const
      80                 : {
      81               0 :   return nsHTMLTags::GetStringValue((nsHTMLTag)aId);
      82                 : }
      83                 :   
      84                 : nsIAtom*
      85               0 : nsParserService::HTMLIdToAtomTag(PRInt32 aId) const
      86                 : {
      87               0 :   return nsHTMLTags::GetAtom((nsHTMLTag)aId);
      88                 : }
      89                 : 
      90                 : NS_IMETHODIMP
      91               0 : nsParserService::HTMLConvertEntityToUnicode(const nsAString& aEntity,
      92                 :                                             PRInt32* aUnicode) const
      93                 : {
      94               0 :   *aUnicode = nsHTMLEntities::EntityToUnicode(aEntity);
      95                 : 
      96               0 :   return NS_OK;
      97                 : }
      98                 : 
      99                 : NS_IMETHODIMP
     100               0 : nsParserService::HTMLConvertUnicodeToEntity(PRInt32 aUnicode,
     101                 :                                             nsCString& aEntity) const
     102                 : {
     103               0 :   const char* str = nsHTMLEntities::UnicodeToEntity(aUnicode);
     104               0 :   if (str) {
     105               0 :     aEntity.Assign(str);
     106                 :   }
     107                 : 
     108               0 :   return NS_OK;
     109                 : }
     110                 : 
     111                 : NS_IMETHODIMP
     112               4 : nsParserService::IsContainer(PRInt32 aId, bool& aIsContainer) const
     113                 : {
     114               4 :   aIsContainer = nsHTMLElement::IsContainer((eHTMLTags)aId);
     115                 : 
     116               4 :   return NS_OK;
     117                 : }
     118                 : 
     119                 : NS_IMETHODIMP
     120               6 : nsParserService::IsBlock(PRInt32 aId, bool& aIsBlock) const
     121                 : {
     122               6 :   if((aId>eHTMLTag_unknown) && (aId<eHTMLTag_userdefined)) {
     123               0 :     aIsBlock=((gHTMLElements[aId].IsMemberOf(kBlock))       ||
     124               0 :               (gHTMLElements[aId].IsMemberOf(kBlockEntity)) ||
     125               0 :               (gHTMLElements[aId].IsMemberOf(kHeading))     ||
     126               0 :               (gHTMLElements[aId].IsMemberOf(kPreformatted))||
     127               0 :               (gHTMLElements[aId].IsMemberOf(kList)));
     128                 :   }
     129                 :   else {
     130               6 :     aIsBlock = false;
     131                 :   }
     132                 : 
     133               6 :   return NS_OK;
     134                 : }
     135                 : 
     136                 : nsresult
     137            2061 : nsParserService::CheckQName(const nsAString& aQName,
     138                 :                             bool aNamespaceAware,
     139                 :                             const PRUnichar** aColon)
     140                 : {
     141                 :   const char* colon;
     142                 :   const PRUnichar *begin, *end;
     143            2061 :   begin = aQName.BeginReading();
     144            2061 :   end = aQName.EndReading();
     145                 :   int result = MOZ_XMLCheckQName(reinterpret_cast<const char*>(begin),
     146                 :                                  reinterpret_cast<const char*>(end),
     147            2061 :                                  aNamespaceAware, &colon);
     148            2061 :   *aColon = reinterpret_cast<const PRUnichar*>(colon);
     149                 : 
     150            2061 :   if (result == 0) {
     151            2061 :     return NS_OK;
     152                 :   }
     153                 : 
     154                 :   // MOZ_EXPAT_EMPTY_QNAME || MOZ_EXPAT_INVALID_CHARACTER
     155               0 :   if (result == (1 << 0) || result == (1 << 1)) {
     156               0 :     return NS_ERROR_DOM_INVALID_CHARACTER_ERR;
     157                 :   }
     158                 : 
     159               0 :   return NS_ERROR_DOM_NAMESPACE_ERR;
     160                 : }

Generated by: LCOV version 1.7