1. internal static int GetKeyValuePair(string connectionString, int currentPosition, StringBuilder buffer, bool useOdbcRules, out string keyname, out string keyvalue)
  2. {
  3.     char chr;
  4.     int num = currentPosition;
  5.     buffer.Length = 0;
  6.     keyname = null;
  7.     keyvalue = null;
  8.     ParserState parserState = ParserState.NothingYet;
  9.     int length = connectionString.Length;
  10. Label8:
  11.     while (currentPosition < length)
  12.     {
  13.         chr = connectionString[currentPosition];
  14.         ParserState parserState1 = parserState;
  15.         if (parserState1 == ParserState.NothingYet)
  16.         {
  17.             if (59 == chr || char.IsWhiteSpace(chr))
  18.             {
  19.                 goto Label2;
  20.             }
  21.             if (chr != 0)
  22.             {
  23.                 if (!char.IsControl(chr))
  24.                 {
  25.                     num = currentPosition;
  26.                     if (61 == chr)
  27.                     {
  28.                         parserState = ParserState.KeyEqual;
  29.                         goto Label2;
  30.                     }
  31.                     else
  32.                     {
  33.                         parserState = ParserState.Key;
  34.                     }
  35.                 }
  36.                 else
  37.                 {
  38.                     throw ADP.ConnectionStringSyntax(num);
  39.                 }
  40.             }
  41.             else
  42.             {
  43.                 parserState = ParserState.NullTermination;
  44.                 goto Label2;
  45.             }
  46.         }
  47.         else if (parserState1 == ParserState.Key)
  48.         {
  49.             if (61 != chr)
  50.             {
  51.                 if (char.IsWhiteSpace(chr) || !char.IsControl(chr))
  52.                 {
  53.                     goto Label4;
  54.                 }
  55.                 throw ADP.ConnectionStringSyntax(num);
  56.             }
  57.             else
  58.             {
  59.                 parserState = ParserState.KeyEqual;
  60.                 goto Label2;
  61.             }
  62.         }
  63.         else if (parserState1 == ParserState.KeyEqual)
  64.         {
  65.             if (useOdbcRules || 61 != chr)
  66.             {
  67.                 keyname = DbConnectionOptions.GetKeyName(buffer);
  68.                 if (!ADP.IsEmpty(ref keyname))
  69.                 {
  70.                     buffer.Length = 0;
  71.                     parserState = ParserState.KeyEnd;
  72.                     goto Label0;
  73.                 }
  74.                 else
  75.                 {
  76.                     throw ADP.ConnectionStringSyntax(num);
  77.                 }
  78.             }
  79.             else
  80.             {
  81.                 parserState = ParserState.Key;
  82.             }
  83.         }
  84.         else if (parserState1 == ParserState.KeyEnd)
  85.         {
  86.             goto Label0;
  87.         }
  88.         else if (parserState1 == ParserState.UnquotedValue)
  89.         {
  90.             if (char.IsWhiteSpace(chr))
  91.             {
  92.                 goto Label4;
  93.             }
  94.             if (char.IsControl(chr))
  95.             {
  96.                 break;
  97.             }
  98.             if (59 != chr)
  99.             {
  100.                 goto Label4;
  101.             }
  102.             break;
  103.         }
  104.         else if (parserState1 == ParserState.DoubleQuoteValue)
  105.         {
  106.             if (34 != chr)
  107.             {
  108.                 if (chr != 0)
  109.                 {
  110.                     goto Label4;
  111.                 }
  112.                 throw ADP.ConnectionStringSyntax(num);
  113.             }
  114.             else
  115.             {
  116.                 parserState = ParserState.DoubleQuoteValueQuote;
  117.                 goto Label2;
  118.             }
  119.         }
  120.         else if (parserState1 == ParserState.DoubleQuoteValueQuote)
  121.         {
  122.             if (34 != chr)
  123.             {
  124.                 keyvalue = DbConnectionOptions.GetKeyValue(buffer, false);
  125.                 parserState = ParserState.QuotedValueEnd;
  126.                 goto Label1;
  127.             }
  128.             else
  129.             {
  130.                 parserState = ParserState.DoubleQuoteValue;
  131.             }
  132.         }
  133.         else if (parserState1 == ParserState.SingleQuoteValue)
  134.         {
  135.             if (39 != chr)
  136.             {
  137.                 if (chr != 0)
  138.                 {
  139.                     goto Label4;
  140.                 }
  141.                 throw ADP.ConnectionStringSyntax(num);
  142.             }
  143.             else
  144.             {
  145.                 parserState = ParserState.SingleQuoteValueQuote;
  146.                 goto Label2;
  147.             }
  148.         }
  149.         else if (parserState1 == ParserState.SingleQuoteValueQuote)
  150.         {
  151.             if (39 != chr)
  152.             {
  153.                 keyvalue = DbConnectionOptions.GetKeyValue(buffer, false);
  154.                 parserState = ParserState.QuotedValueEnd;
  155.                 goto Label1;
  156.             }
  157.             else
  158.             {
  159.                 parserState = ParserState.SingleQuoteValue;
  160.             }
  161.         }
  162.         else if (parserState1 == ParserState.BraceQuoteValue)
  163.         {
  164.             if (125 != chr)
  165.             {
  166.                 if (chr != 0)
  167.                 {
  168.                     goto Label4;
  169.                 }
  170.                 throw ADP.ConnectionStringSyntax(num);
  171.             }
  172.             else
  173.             {
  174.                 parserState = ParserState.BraceQuoteValueQuote;
  175.             }
  176.         }
  177.         else if (parserState1 == ParserState.BraceQuoteValueQuote)
  178.         {
  179.             if (125 != chr)
  180.             {
  181.                 keyvalue = DbConnectionOptions.GetKeyValue(buffer, false);
  182.                 parserState = ParserState.QuotedValueEnd;
  183.                 goto Label1;
  184.             }
  185.             else
  186.             {
  187.                 parserState = ParserState.BraceQuoteValue;
  188.             }
  189.         }
  190.         else if (parserState1 == ParserState.QuotedValueEnd)
  191.         {
  192.             goto Label1;
  193.         }
  194.         else if (parserState1 == ParserState.NullTermination)
  195.         {
  196.             if (chr == 0 || char.IsWhiteSpace(chr))
  197.             {
  198.                 goto Label2;
  199.             }
  200.             throw ADP.ConnectionStringSyntax(currentPosition);
  201.         }
  202.         else
  203.         {
  204.             throw ADP.InternalError(InternalErrorCode.InvalidParserState1);
  205.         }
  206.     Label4:
  207.         buffer.Append(chr);
  208.         goto Label2;
  209.     }
  210.     ParserState parserState2 = parserState;
  211.     switch (parserState2)
  212.     {
  213.         case ParserState.KeyEqual:
  214.         case ParserState.DoubleQuoteValue:
  215.         case ParserState.NothingYet | ParserState.Key | ParserState.KeyEqual | ParserState.KeyEnd | ParserState.UnquotedValue | ParserState.DoubleQuoteValue | ParserState.DoubleQuoteValueQuote | ParserState.SingleQuoteValue | ParserState.SingleQuoteValueQuote | ParserState.BraceQuoteValue | ParserState.BraceQuoteValueQuote | ParserState.QuotedValueEnd | ParserState.NullTermination:
  216.         {
  217.             if (59 == chr && currentPosition < connectionString.Length)
  218.             {
  219.                 currentPosition++;
  220.             }
  221.             return currentPosition;
  222.         }
  223.         case ParserState.KeyEnd:
  224.         case ParserState.SingleQuoteValue:
  225.         case ParserState.BraceQuoteValue:
  226.         case ParserState.QuotedValueEnd:
  227.         {
  228.             throw ADP.ConnectionStringSyntax(num);
  229.         }
  230.         case ParserState.UnquotedValue:
  231.         {
  232.             keyname = DbConnectionOptions.GetKeyName(buffer);
  233.             if (!ADP.IsEmpty(ref keyname))
  234.             {
  235.                 if (59 == chr && currentPosition < connectionString.Length)
  236.                 {
  237.                     currentPosition++;
  238.                 }
  239.                 return currentPosition;
  240.             }
  241.             throw ADP.ConnectionStringSyntax(num);
  242.         }
  243.         case ParserState.DoubleQuoteValueQuote:
  244.         {
  245.             keyvalue = DbConnectionOptions.GetKeyValue(buffer, true);
  246.             char chars = keyvalue.Chars;
  247.             if (useOdbcRules || 39 != chars && 34 != chars)
  248.             {
  249.                 if (59 == chr && currentPosition < connectionString.Length)
  250.                 {
  251.                     currentPosition++;
  252.                 }
  253.                 return currentPosition;
  254.             }
  255.             throw ADP.ConnectionStringSyntax(num);
  256.         }
  257.         case ParserState.SingleQuoteValueQuote:
  258.         case ParserState.BraceQuoteValueQuote:
  259.         case ParserState.NullTermination:
  260.         case ParserState.Key | ParserState.KeyEnd | ParserState.DoubleQuoteValue | ParserState.SingleQuoteValue | ParserState.BraceQuoteValue | ParserState.QuotedValueEnd:
  261.         {
  262.             keyvalue = DbConnectionOptions.GetKeyValue(buffer, false);
  263.             if (59 == chr && currentPosition < connectionString.Length)
  264.             {
  265.                 currentPosition++;
  266.             }
  267.             return currentPosition;
  268.         }
  269.     }
  270.     throw ADP.InternalError(InternalErrorCode.InvalidParserState2);
  271. Label0:
  272.     if (!char.IsWhiteSpace(chr))
  273.     {
  274.         if (!useOdbcRules)
  275.         {
  276.             if (39 != chr)
  277.             {
  278.                 if (34 != chr)
  279.                 {
  280.                     goto Label7;
  281.                 }
  282.                 parserState = ParserState.DoubleQuoteValue;
  283.                 goto Label2;
  284.             }
  285.             else
  286.             {
  287.                 parserState = ParserState.SingleQuoteValue;
  288.                 goto Label2;
  289.             }
  290.         }
  291.         else
  292.         {
  293.             if (123 != chr)
  294.             {
  295.                 goto Label7;
  296.             }
  297.             parserState = ParserState.BraceQuoteValue;
  298.             goto Label4;
  299.         }
  300.     Label7:
  301.         if (59 == chr || chr == 0)
  302.         {
  303.             parserState2 = parserState;
  304.             switch (parserState2)
  305.             {
  306.                 case ParserState.KeyEqual:
  307.                 case ParserState.DoubleQuoteValue:
  308.                 case ParserState.NothingYet | ParserState.Key | ParserState.KeyEqual | ParserState.KeyEnd | ParserState.UnquotedValue | ParserState.DoubleQuoteValue | ParserState.DoubleQuoteValueQuote | ParserState.SingleQuoteValue | ParserState.SingleQuoteValueQuote | ParserState.BraceQuoteValue | ParserState.BraceQuoteValueQuote | ParserState.QuotedValueEnd | ParserState.NullTermination:
  309.                 {
  310.                     if (59 == chr && currentPosition < connectionString.Length)
  311.                     {
  312.                         currentPosition++;
  313.                     }
  314.                     return currentPosition;
  315.                 }
  316.                 case ParserState.KeyEnd:
  317.                 case ParserState.SingleQuoteValue:
  318.                 case ParserState.BraceQuoteValue:
  319.                 case ParserState.QuotedValueEnd:
  320.                 {
  321.                     throw ADP.ConnectionStringSyntax(num);
  322.                 }
  323.                 case ParserState.UnquotedValue:
  324.                 {
  325.                     keyname = DbConnectionOptions.GetKeyName(buffer);
  326.                     if (!ADP.IsEmpty(ref keyname))
  327.                     {
  328.                         if (59 == chr && currentPosition < connectionString.Length)
  329.                         {
  330.                             currentPosition++;
  331.                         }
  332.                         return currentPosition;
  333.                     }
  334.                     throw ADP.ConnectionStringSyntax(num);
  335.                 }
  336.                 case ParserState.DoubleQuoteValueQuote:
  337.                 {
  338.                     keyvalue = DbConnectionOptions.GetKeyValue(buffer, true);
  339.                     char chars = keyvalue.Chars;
  340.                     if (useOdbcRules || 39 != chars && 34 != chars)
  341.                     {
  342.                         if (59 == chr && currentPosition < connectionString.Length)
  343.                         {
  344.                             currentPosition++;
  345.                         }
  346.                         return currentPosition;
  347.                     }
  348.                     throw ADP.ConnectionStringSyntax(num);
  349.                 }
  350.                 case ParserState.SingleQuoteValueQuote:
  351.                 case ParserState.BraceQuoteValueQuote:
  352.                 case ParserState.NullTermination:
  353.                 case ParserState.Key | ParserState.KeyEnd | ParserState.DoubleQuoteValue | ParserState.SingleQuoteValue | ParserState.BraceQuoteValue | ParserState.QuotedValueEnd:
  354.                 {
  355.                     keyvalue = DbConnectionOptions.GetKeyValue(buffer, false);
  356.                     if (59 == chr && currentPosition < connectionString.Length)
  357.                     {
  358.                         currentPosition++;
  359.                     }
  360.                     return currentPosition;
  361.                 }
  362.             }
  363.             throw ADP.InternalError(InternalErrorCode.InvalidParserState2);
  364.         }
  365.         if (!char.IsControl(chr))
  366.         {
  367.             parserState = ParserState.UnquotedValue;
  368.             goto Label4;
  369.         }
  370.         else
  371.         {
  372.             throw ADP.ConnectionStringSyntax(num);
  373.         }
  374.     }
  375. Label2:
  376.     currentPosition++;
  377.     goto Label8;
  378. Label1:
  379.     if (!char.IsWhiteSpace(chr))
  380.     {
  381.         if (59 == chr)
  382.         {
  383.             parserState2 = parserState;
  384.             switch (parserState2)
  385.             {
  386.                 case ParserState.KeyEqual:
  387.                 case ParserState.DoubleQuoteValue:
  388.                 case ParserState.NothingYet | ParserState.Key | ParserState.KeyEqual | ParserState.KeyEnd | ParserState.UnquotedValue | ParserState.DoubleQuoteValue | ParserState.DoubleQuoteValueQuote | ParserState.SingleQuoteValue | ParserState.SingleQuoteValueQuote | ParserState.BraceQuoteValue | ParserState.BraceQuoteValueQuote | ParserState.QuotedValueEnd | ParserState.NullTermination:
  389.                 {
  390.                     if (59 == chr && currentPosition < connectionString.Length)
  391.                     {
  392.                         currentPosition++;
  393.                     }
  394.                     return currentPosition;
  395.                 }
  396.                 case ParserState.KeyEnd:
  397.                 case ParserState.SingleQuoteValue:
  398.                 case ParserState.BraceQuoteValue:
  399.                 case ParserState.QuotedValueEnd:
  400.                 {
  401.                     throw ADP.ConnectionStringSyntax(num);
  402.                 }
  403.                 case ParserState.UnquotedValue:
  404.                 {
  405.                     keyname = DbConnectionOptions.GetKeyName(buffer);
  406.                     if (!ADP.IsEmpty(ref keyname))
  407.                     {
  408.                         if (59 == chr && currentPosition < connectionString.Length)
  409.                         {
  410.                             currentPosition++;
  411.                         }
  412.                         return currentPosition;
  413.                     }
  414.                     throw ADP.ConnectionStringSyntax(num);
  415.                 }
  416.                 case ParserState.DoubleQuoteValueQuote:
  417.                 {
  418.                     keyvalue = DbConnectionOptions.GetKeyValue(buffer, true);
  419.                     char chars = keyvalue.Chars;
  420.                     if (useOdbcRules || 39 != chars && 34 != chars)
  421.                     {
  422.                         if (59 == chr && currentPosition < connectionString.Length)
  423.                         {
  424.                             currentPosition++;
  425.                         }
  426.                         return currentPosition;
  427.                     }
  428.                     throw ADP.ConnectionStringSyntax(num);
  429.                 }
  430.                 case ParserState.SingleQuoteValueQuote:
  431.                 case ParserState.BraceQuoteValueQuote:
  432.                 case ParserState.NullTermination:
  433.                 case ParserState.Key | ParserState.KeyEnd | ParserState.DoubleQuoteValue | ParserState.SingleQuoteValue | ParserState.BraceQuoteValue | ParserState.QuotedValueEnd:
  434.                 {
  435.                     keyvalue = DbConnectionOptions.GetKeyValue(buffer, false);
  436.                     if (59 == chr && currentPosition < connectionString.Length)
  437.                     {
  438.                         currentPosition++;
  439.                     }
  440.                     return currentPosition;
  441.                 }
  442.             }
  443.             throw ADP.InternalError(InternalErrorCode.InvalidParserState2);
  444.         }
  445.         if (chr != 0)
  446.         {
  447.             throw ADP.ConnectionStringSyntax(num);
  448.         }
  449.         else
  450.         {
  451.             parserState = ParserState.NullTermination;
  452.             goto Label2;
  453.         }
  454.     }
  455.     else
  456.     {
  457.         goto Label2;
  458.     }
  459. }