Tag: cws_src680_qiq
User: fs      
Date: 06/06/07 01:59:01

Modified:
 /dba/connectivity/source/parse/
  sqlNoException.cxx

Log:
 during #i51143#: don't create double bracket pairs (e.g. 'WHERE ( ( A = B ) 
)') if not necessary

File Changes:

Directory: /dba/connectivity/source/parse/
==========================================

File [changed]: sqlNoException.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/connectivity/source/parse/sqlNoException.cxx?r1=1.20.104.1&r2=1.20.104.2
Delta lines:  +47 -5
--------------------
--- sqlNoException.cxx  10 May 2006 10:23:46 -0000      1.20.104.1
+++ sqlNoException.cxx  7 Jun 2006 08:58:58 -0000       1.20.104.2
@@ -4,9 +4,9 @@
  *
  *  $RCSfile: sqlNoException.cxx,v $
  *
- *  $Revision: 1.20.104.1 $
+ *  $Revision: 1.20.104.2 $
  *
- *  last change: $Author: fs $ $Date: 2006/05/10 10:23:46 $
+ *  last change: $Author: fs $ $Date: 2006/06/07 08:58:58 $
  *
  *  The Contents of this file are made available subject to
  *  the terms of GNU Lesser General Public License Version 2.1.
@@ -890,6 +890,27 @@
        ::std::replace(m_aChilds.begin(), m_aChilds.end(), pOldSubNode, 
pNewSubNode);
        return pOldSubNode;
 }
+
+// 
-----------------------------------------------------------------------------
+namespace
+{
+    // checks whether the left-most and the right-most sibling of a parse node
+    // are brackets: '(' and ')', respectively
+    static bool lcl_hasEnclosingBrackets( const OSQLParseNode& _rNode )
+    {
+        const OSQLParseNode* pParent( _rNode.getParent() );
+        if ( !pParent || pParent->count() < 2 )
+            return false;
+
+        if  (   SQL_ISPUNCTUATION( pParent->getChild( 0                    ), 
"(" )
+            &&  SQL_ISPUNCTUATION( pParent->getChild( pParent->count() - 1 ), 
")" )
+            )
+            return true;
+
+        return false;
+    }
+}
+
 // 
-----------------------------------------------------------------------------
 void OSQLParseNode::parseLeaf(::rtl::OUString & rString, const 
SQLParseNodeParameter& rParam) const
 {
@@ -943,6 +964,7 @@
                        rString += m_aNodeValue;
                        rString += ::rtl::OUString::createFromAscii("#");
                        break;
+
                case SQL_NODE_INTNUM:
                case SQL_NODE_APPROXNUM:
                        {
@@ -954,8 +976,28 @@
                                        rString += 
::rtl::OUString::createFromAscii(" ");
                                rString += aTmp;
 
-                       }       break;
+                       }
+            break;
+
+        case SQL_NODE_PUNCTUATION:
+        {
+            const OSQLParseNode* pParent( getParent() );
+
+            bool bLastChild = ( pParent != NULL ) && ( pParent->getChild( 
pParent->count() - 1 ) == this );
+            bool bFirstChild = ( pParent != NULL ) && ( pParent->getChild( 0 ) 
== this );
+
+            if ( ( bLastChild || bFirstChild ) && lcl_hasEnclosingBrackets( 
*this ) && lcl_hasEnclosingBrackets( *pParent ) )
+                // our left-most sibling is an opening bracket, our right-most 
sibling is a closing bracket.
+                // The same holds for the left-most and right-most siblings of 
our parent:
+                //        / | \
+                //      '(' P ')'       (P = parent node)
+                //        / | \
+                //      '(' t ')'       (t = this)
+                // This means we can spare one pair of brackets ... (can't we?)
+                break;
+        }
                        // fall through
+
                default:
                        if (rString.getLength() && m_aNodeValue.toChar() != '.' 
&& m_aNodeValue.toChar() != ':' )
                        {




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to