]> git.saurik.com Git - wxWidgets.git/commitdiff
Avoid using wxHtmlTag::HasParam() unnecessarily.
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 30 Sep 2013 23:48:46 +0000 (23:48 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 30 Sep 2013 23:48:46 +0000 (23:48 +0000)
Use GetParamAsXXX() accessors instead as they combine the calls to HasParam()
and GetParam() and make the code shorter and avoid the duplication of the tag
name.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74881 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/html/htmlcell.cpp
src/html/htmlpars.cpp
src/html/m_fonts.cpp
src/html/m_image.cpp
src/html/m_layout.cpp
src/html/m_links.cpp
src/html/m_tables.cpp

index 9ae76f328ea7b5c45fc3fd8601c1e7ea20dc04fe..1d247d35c2d6ee9e5f2553375a95d5f45810991c 100644 (file)
@@ -1264,9 +1264,9 @@ void wxHtmlContainerCell::InsertCell(wxHtmlCell *f)
 
 void wxHtmlContainerCell::SetAlign(const wxHtmlTag& tag)
 {
-    if (tag.HasParam(wxT("ALIGN")))
+    wxString alg;
+    if (tag.GetParamAsString(wxT("ALIGN"), &alg))
     {
-        wxString alg = tag.GetParam(wxT("ALIGN"));
         alg.MakeUpper();
         if (alg == wxT("CENTER"))
             SetAlignHor(wxHTML_ALIGN_CENTER);
@@ -1284,19 +1284,16 @@ void wxHtmlContainerCell::SetAlign(const wxHtmlTag& tag)
 
 void wxHtmlContainerCell::SetWidthFloat(const wxHtmlTag& tag, double pixel_scale)
 {
-    if (tag.HasParam(wxT("WIDTH")))
+    int wdi;
+    bool wpercent;
+    if (tag.GetParamAsIntOrPercent(wxT("WIDTH"), &wdi, wpercent))
     {
-        int wdi;
-        wxString wd = tag.GetParam(wxT("WIDTH"));
-
-        if (wd[wd.length()-1] == wxT('%'))
+        if (wpercent)
         {
-            wxSscanf(wd.c_str(), wxT("%i%%"), &wdi);
             SetWidthFloat(wdi, wxHTML_UNITS_PERCENT);
         }
         else
         {
-            wxSscanf(wd.c_str(), wxT("%i"), &wdi);
             SetWidthFloat((int)(pixel_scale * (double)wdi), wxHTML_UNITS_PIXELS);
         }
         m_LastLayout = -1;
index 0e38da7bc4b3d1a60bb55aec9b26b10032c1163c..308df6922a82aab6dca3a5558968c4964983ffb1 100644 (file)
@@ -918,11 +918,13 @@ bool wxMetaTagHandler::HandleTag(const wxHtmlTag& tag)
         return false;
     }
 
-    if (tag.HasParam(wxT("HTTP-EQUIV")) &&
-        tag.GetParam(wxT("HTTP-EQUIV")).IsSameAs(wxT("Content-Type"), false) &&
-        tag.HasParam(wxT("CONTENT")))
+    wxString httpEquiv,
+             content;
+    if (tag.GetParamAsString(wxT("HTTP-EQUIV"), &httpEquiv) &&
+        httpEquiv.IsSameAs(wxT("Content-Type"), false) &&
+        tag.GetParamAsString(wxT("CONTENT"), &content))
     {
-        wxString content = tag.GetParam(wxT("CONTENT")).Lower();
+        content.MakeLower();
         if (content.Left(19) == wxT("text/html; charset="))
         {
             *m_retval = content.Mid(19);
index ab4fce6f9564201e37bca5081326b7e85a200e2f..117f8faca9d9fac1e90550ca055f689a9de880d4 100644 (file)
@@ -38,7 +38,6 @@ TAG_HANDLER_BEGIN(FONT, "FONT" )
         int oldsize = m_WParser->GetFontSize();
         wxString oldface = m_WParser->GetFontFace();
 
-        if (tag.HasParam(wxT("COLOR")))
         {
             wxColour clr;
             if (tag.GetParamAsColour(wxT("COLOR"), &clr))
@@ -48,11 +47,10 @@ TAG_HANDLER_BEGIN(FONT, "FONT" )
             }
         }
 
-        if (tag.HasParam(wxT("SIZE")))
         {
             long tmp = 0;
-            const wxString sizeStr = tag.GetParam(wxT("SIZE"));
-            if (sizeStr.ToLong(&tmp))
+            wxString sizeStr;
+            if (tag.GetParamAsString(wxT("SIZE"), &sizeStr) && sizeStr.ToLong(&tmp))
             {
                 wxChar c = sizeStr[0];
                 if (c == wxT('+') || c == wxT('-'))
@@ -64,12 +62,13 @@ TAG_HANDLER_BEGIN(FONT, "FONT" )
             }
         }
 
-        if (tag.HasParam(wxT("FACE")))
+        wxString faces;
+        if (tag.GetParamAsString(wxT("FACE"), &faces))
         {
             if (m_Faces.GetCount() == 0)
                 m_Faces = wxFontEnumerator::GetFacenames();
 
-            wxStringTokenizer tk(tag.GetParam(wxT("FACE")), wxT(","));
+            wxStringTokenizer tk(faces, wxT(","));
             int index;
 
             while (tk.HasMoreTokens())
index d1f550212e571f72b688092b94558381e305ab59..482692b64963a4400fbdbaef75c8e85a702f5302 100644 (file)
@@ -661,51 +661,46 @@ TAG_HANDLER_BEGIN(IMG, "IMG,MAP,AREA")
     {
         if (tag.GetName() == wxT("IMG"))
         {
-            if (tag.HasParam(wxT("SRC")))
+            wxString tmp;
+            if (tag.GetParamAsString(wxT("SRC"), &tmp))
             {
                 int w = wxDefaultCoord, h = wxDefaultCoord;
                 bool wpercent = false;
                 bool hpresent = false;
                 int al;
                 wxFSFile *str;
-                wxString tmp = tag.GetParam(wxT("SRC"));
-                wxString mn = wxEmptyString;
+                wxString mn;
 
                 str = m_WParser->OpenURL(wxHTML_URL_IMAGE, tmp);
 
-                if (tag.HasParam(wxT("WIDTH")))
+                if (tag.GetParamAsIntOrPercent(wxT("WIDTH"), &w, wpercent))
                 {
-                    if (tag.GetParamAsIntOrPercent(wxT("WIDTH"), &w, wpercent))
+                    if (wpercent)
                     {
-                        if (wpercent)
-                        {
-                            if (w < 0)
-                                w = 0;
-                            else if (w > 100)
-                                w = 100;
-                        }
+                        if (w < 0)
+                            w = 0;
+                        else if (w > 100)
+                            w = 100;
                     }
                 }
 
-                if (tag.HasParam(wxT("HEIGHT")))
+                if (tag.GetParamAsInt(wxT("HEIGHT"), &h))
                 {
-                    tag.GetParamAsInt(wxT("HEIGHT"), &h);
                     hpresent = true;
                 }
 
                 al = wxHTML_ALIGN_BOTTOM;
-                if (tag.HasParam(wxT("ALIGN")))
+                wxString alstr;
+                if (tag.GetParamAsString(wxT("ALIGN"), &alstr))
                 {
-                    wxString alstr = tag.GetParam(wxT("ALIGN"));
                     alstr.MakeUpper();  // for the case alignment was in ".."
                     if (alstr == wxT("TEXTTOP"))
                         al = wxHTML_ALIGN_TOP;
                     else if ((alstr == wxT("CENTER")) || (alstr == wxT("ABSCENTER")))
                         al = wxHTML_ALIGN_CENTER;
                 }
-                if (tag.HasParam(wxT("USEMAP")))
+                if (tag.GetParamAsString(wxT("USEMAP"), &mn))
                 {
-                    mn = tag.GetParam( wxT("USEMAP") );
                     if ( !mn.empty() && *mn.begin() == '#' )
                     {
                         mn = mn.Mid( 1 );
@@ -729,9 +724,9 @@ TAG_HANDLER_BEGIN(IMG, "IMG,MAP,AREA")
         {
             m_WParser->CloseContainer();
             m_WParser->OpenContainer();
-            if (tag.HasParam(wxT("NAME")))
+            wxString tmp;
+            if (tag.GetParamAsString(wxT("NAME"), &tmp))
             {
-                wxString tmp = tag.GetParam(wxT("NAME"));
                 wxHtmlImageMapCell *cel = new wxHtmlImageMapCell( tmp );
                 m_WParser->GetContainer()->InsertCell( cel );
             }
@@ -741,16 +736,12 @@ TAG_HANDLER_BEGIN(IMG, "IMG,MAP,AREA")
         }
         if (tag.GetName() == wxT("AREA"))
         {
-            if (tag.HasParam(wxT("SHAPE")))
+            wxString tmp;
+            if (tag.GetParamAsString(wxT("SHAPE"), &tmp))
             {
-                wxString tmp = tag.GetParam(wxT("SHAPE"));
-                wxString coords = wxEmptyString;
+                wxString coords = tag.GetParam(wxT("COORDS"));
                 tmp.MakeUpper();
                 wxHtmlImageMapAreaCell *cel = NULL;
-                if (tag.HasParam(wxT("COORDS")))
-                {
-                    coords = tag.GetParam(wxT("COORDS"));
-                }
                 if (tmp == wxT("POLY"))
                 {
                     cel = new wxHtmlImageMapAreaCell( wxHtmlImageMapAreaCell::POLY, coords, m_WParser->GetPixelScale() );
@@ -763,13 +754,9 @@ TAG_HANDLER_BEGIN(IMG, "IMG,MAP,AREA")
                 {
                     cel = new wxHtmlImageMapAreaCell( wxHtmlImageMapAreaCell::RECT, coords, m_WParser->GetPixelScale() );
                 }
-                if (cel != NULL && tag.HasParam(wxT("HREF")))
-                {
-                    wxString target;
-                    if (tag.HasParam(wxT("TARGET")))
-                        target = tag.GetParam(wxT("TARGET"));
-                    cel->SetLink(wxHtmlLinkInfo(tag.GetParam(wxT("HREF")), target));
-                }
+                wxString href;
+                if (cel != NULL && tag.GetParamAsString(wxT("HREF"), &href))
+                    cel->SetLink(wxHtmlLinkInfo(href, tag.GetParam(wxT("TARGET"))));
                 if (cel != NULL)
                     m_WParser->GetContainer()->InsertCell( cel );
             }
index 5bd061956156803171d75f8d0bc767c691c70103..0bc769bf52a9df36c4fc9b5389e549f7e81996bc 100644 (file)
@@ -212,9 +212,10 @@ TAG_HANDLER_BEGIN(DIV, "DIV")
 
     TAG_HANDLER_PROC(tag)
     {
-        if(tag.HasParam(wxT("STYLE")))
+        wxString style;
+        if(tag.GetParamAsString(wxT("STYLE"), &style))
         {
-            if(tag.GetParam(wxT("STYLE")).IsSameAs(wxT("PAGE-BREAK-BEFORE:ALWAYS"), false))
+            if(style.IsSameAs(wxT("PAGE-BREAK-BEFORE:ALWAYS"), false))
             {
                 m_WParser->CloseContainer();
                 m_WParser->OpenContainer()->InsertCell(new wxHtmlPageBreakCell);
@@ -330,13 +331,10 @@ TAG_HANDLER_BEGIN(BODY, "BODY")
         if ( !winIface )
             return false;
 
-        if (tag.HasParam(wxT("BACKGROUND")))
+        wxString bg;
+        if (tag.GetParamAsString(wxT("BACKGROUND"), &bg))
         {
-            wxFSFile *fileBgImage = m_WParser->OpenURL
-                                               (
-                                                wxHTML_URL_IMAGE,
-                                                tag.GetParam(wxT("BACKGROUND"))
-                                               );
+            wxFSFile *fileBgImage = m_WParser->OpenURL(wxHTML_URL_IMAGE, bg);
             if ( fileBgImage )
             {
                 wxInputStream *is = fileBgImage->GetStream();
index ec482a88e64163e1f2e6461ac9cd03817c6a20cb..4dfebdc2e6400dc66721b62dc61f081ad46411dd 100644 (file)
@@ -61,12 +61,14 @@ TAG_HANDLER_BEGIN(A, "A")
 
     TAG_HANDLER_PROC(tag)
     {
-        if (tag.HasParam( wxT("NAME") ))
+        wxString name;
+        if (tag.GetParamAsString(wxT("NAME"), &name))
         {
-            m_WParser->GetContainer()->InsertCell(new wxHtmlAnchorCell(tag.GetParam( wxT("NAME") )));
+            m_WParser->GetContainer()->InsertCell(new wxHtmlAnchorCell(name));
         }
 
-        if (tag.HasParam( wxT("HREF") ))
+        wxString href;
+        if (tag.GetParamAsString(wxT("HREF"), &href))
         {
             wxHtmlLinkInfo oldlnk = m_WParser->GetLink();
             wxColour oldclr = m_WParser->GetActualColor();
@@ -77,16 +79,14 @@ TAG_HANDLER_BEGIN(A, "A")
             int olditalic = m_WParser->GetFontItalic();
             int oldund = m_WParser->GetFontUnderlined();
             wxString oldfontface = m_WParser->GetFontFace();
-            wxString name(tag.GetParam( wxT("HREF") )), target;
-
-            if (tag.HasParam( wxT("TARGET") )) target = tag.GetParam( wxT("TARGET") );
+            wxString target = tag.GetParam( wxT("TARGET") );
 
             // set default styles, might get overridden by ApplyStyle
             m_WParser->SetActualColor(m_WParser->GetLinkColor());
             m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(m_WParser->GetLinkColor()));
             m_WParser->SetFontUnderlined(true);
             m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
-            m_WParser->SetLink(wxHtmlLinkInfo(name, target));
+            m_WParser->SetLink(wxHtmlLinkInfo(href, target));
 
             // Load any style parameters
             wxHtmlStyleParams styleParams(tag);
index cbd27237381ea9aa94a139f623c307659bbda6b1..25f3f96b7c7982fdab178d1822550250b6336d50 100644 (file)
@@ -134,16 +134,9 @@ wxHtmlTableCell::wxHtmlTableCell(wxHtmlContainerCell *parent, const wxHtmlTag& t
     m_ActualCol = m_ActualRow = -1;
 
     /* scan params: */
-    if (tag.HasParam(wxT("BGCOLOR")))
-    {
-        tag.GetParamAsColour(wxT("BGCOLOR"), &m_tBkg);
-        if (m_tBkg.IsOk())
-            SetBackgroundColour(m_tBkg);
-    }
-    if (tag.HasParam(wxT("VALIGN")))
-        m_tValign = tag.GetParam(wxT("VALIGN"));
-    else
-        m_tValign = wxEmptyString;
+    if (tag.GetParamAsColour(wxT("BGCOLOR"), &m_tBkg))
+        SetBackgroundColour(m_tBkg);
+    m_tValign = tag.GetParam(wxT("VALIGN"));
     if (!tag.GetParamAsInt(wxT("CELLSPACING"), &m_Spacing))
         m_Spacing = 2;
     if (!tag.GetParamAsInt(wxT("CELLPADDING"), &m_Padding))
@@ -242,11 +235,8 @@ void wxHtmlTableCell::AddRow(const wxHtmlTag& tag)
 
     // scan params:
     m_rBkg = m_tBkg;
-    if (tag.HasParam(wxT("BGCOLOR")))
-        tag.GetParamAsColour(wxT("BGCOLOR"), &m_rBkg);
-    if (tag.HasParam(wxT("VALIGN")))
-        m_rValign = tag.GetParam(wxT("VALIGN"));
-    else
+    tag.GetParamAsColour(wxT("BGCOLOR"), &m_rBkg);
+    if (!tag.GetParamAsString(wxT("VALIGN"), &m_rValign))
         m_rValign = m_tValign;
 }
 
@@ -293,25 +283,19 @@ void wxHtmlTableCell::AddCell(wxHtmlContainerCell *cell, const wxHtmlTag& tag)
 
     // width:
     {
-        if (tag.HasParam(wxT("WIDTH")))
+        int width = 0;
+        bool wpercent = false;
+        if (tag.GetParamAsIntOrPercent(wxT("WIDTH"), &width, wpercent))
         {
-            wxString wd = tag.GetParam(wxT("WIDTH"));
-
-            if (!wd.empty() && wd[wd.length()-1] == wxT('%'))
+            if (wpercent)
             {
-                if ( wxSscanf(wd.c_str(), wxT("%i%%"), &m_ColsInfo[c].width) == 1 )
-                {
-                    m_ColsInfo[c].units = wxHTML_UNITS_PERCENT;
-                }
+                m_ColsInfo[c].width = width;
+                m_ColsInfo[c].units = wxHTML_UNITS_PERCENT;
             }
             else
             {
-                long width;
-                if ( wd.ToLong(&width) )
-                {
-                    m_ColsInfo[c].width = (int)(m_PixelScale * (double)width);
-                    m_ColsInfo[c].units = wxHTML_UNITS_PIXELS;
-                }
+                m_ColsInfo[c].width = (int)(m_PixelScale * (double)width);
+                m_ColsInfo[c].units = wxHTML_UNITS_PIXELS;
             }
         }
     }
@@ -351,8 +335,7 @@ void wxHtmlTableCell::AddCell(wxHtmlContainerCell *cell, const wxHtmlTag& tag)
     //background color:
     {
         wxColour bk = m_rBkg;
-        if (tag.HasParam(wxT("BGCOLOR")))
-            tag.GetParamAsColour(wxT("BGCOLOR"), &bk);
+        tag.GetParamAsColour(wxT("BGCOLOR"), &bk);
         if (bk.IsOk())
             cell->SetBackgroundColour(bk);
     }
@@ -362,9 +345,7 @@ void wxHtmlTableCell::AddCell(wxHtmlContainerCell *cell, const wxHtmlTag& tag)
     // vertical alignment:
     {
         wxString valign;
-        if (tag.HasParam(wxT("VALIGN")))
-            valign = tag.GetParam(wxT("VALIGN"));
-        else
+        if (!tag.GetParamAsString(wxT("VALIGN"), &valign))
             valign = m_tValign;
         valign.MakeUpper();
         if (valign == wxT("TOP"))
@@ -375,10 +356,7 @@ void wxHtmlTableCell::AddCell(wxHtmlContainerCell *cell, const wxHtmlTag& tag)
     }
 
     // nowrap
-    if (tag.HasParam(wxT("NOWRAP")))
-        m_CellInfo[r][c].nowrap = true;
-    else
-        m_CellInfo[r][c].nowrap = false;
+    m_CellInfo[r][c].nowrap = tag.HasParam(wxT("NOWRAP"));
 
     cell->SetIndent(m_Padding, wxHTML_INDENT_ALL, wxHTML_UNITS_PIXELS);
 }
@@ -740,29 +718,25 @@ TAG_HANDLER_BEGIN(TABLE, "TABLE,TR,TD,TH")
 
             // width:
             {
-                if (tag.HasParam(wxT("WIDTH")))
+                int width = 0;
+                bool wpercent = false;
+                if (tag.GetParamAsIntOrPercent(wxT("WIDTH"), &width, wpercent))
                 {
-                    int width = 0;
-                    bool wpercent = false;
-                    if (tag.GetParamAsIntOrPercent(wxT("WIDTH"), &width, wpercent))
+                    if (wpercent)
                     {
-                        if (wpercent)
-                        {
-                            m_Table->SetWidthFloat(width, wxHTML_UNITS_PERCENT);
-                        }
-                        else
-                        {
-                            m_Table->SetWidthFloat((int)(m_WParser->GetPixelScale() * width), wxHTML_UNITS_PIXELS);
-                        }
+                        m_Table->SetWidthFloat(width, wxHTML_UNITS_PERCENT);
+                    }
+                    else
+                    {
+                        m_Table->SetWidthFloat((int)(m_WParser->GetPixelScale() * width), wxHTML_UNITS_PIXELS);
                     }
                 }
                 else
                     m_Table->SetWidthFloat(0, wxHTML_UNITS_PIXELS);
             }
             int oldAlign = m_WParser->GetAlign();
-            m_tAlign = wxEmptyString;
-            if (tag.HasParam(wxT("ALIGN")))
-                m_tAlign = tag.GetParam(wxT("ALIGN"));
+            if (!tag.GetParamAsString(wxT("ALIGN"), &m_tAlign))
+                m_tAlign.clear();
 
             CallParseInnerWithBg(tag, m_Table->GetBackgroundColour());
 
@@ -783,9 +757,8 @@ TAG_HANDLER_BEGIN(TABLE, "TABLE,TR,TD,TH")
             if (tag.GetName() == wxT("TR"))
             {
                 m_Table->AddRow(tag);
-                m_rAlign = m_tAlign;
-                if (tag.HasParam(wxT("ALIGN")))
-                    m_rAlign = tag.GetParam(wxT("ALIGN"));
+                if (!tag.GetParamAsString(wxT("ALIGN"), &m_rAlign))
+                    m_rAlign = m_tAlign;
             }
 
             // new cell
@@ -799,9 +772,7 @@ TAG_HANDLER_BEGIN(TABLE, "TABLE,TR,TD,TH")
                 const bool isHeader = tag.GetName() == wxT("TH");
 
                 wxString als;
-                if (tag.HasParam(wxT("ALIGN")))
-                    als = tag.GetParam(wxT("ALIGN"));
-                else
+                if (!tag.GetParamAsString(wxT("ALIGN"), &als))
                     als = m_rAlign;
                 als.MakeUpper();