summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYoussef1313 <31348972+Youssef1313@users.noreply.github.com>2019-06-04 17:30:26 +0200
committerJan Kotas <jkotas@microsoft.com>2019-06-04 08:30:26 -0700
commit8368b69bea1e70933f24a42cf626e90c1266cbfd (patch)
tree1b1a8be16a20ee37de5702a26dac61fdb39a7249 /src
parent87696dda415832b6ca2636ad016b9075aa7778e7 (diff)
downloadcoreclr-8368b69bea1e70933f24a42cf626e90c1266cbfd.tar.gz
coreclr-8368b69bea1e70933f24a42cf626e90c1266cbfd.tar.bz2
coreclr-8368b69bea1e70933f24a42cf626e90c1266cbfd.zip
Being consistent (#24927)
Being consistent using all if statement with curly braces.
Diffstat (limited to 'src')
-rw-r--r--src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs125
1 files changed, 110 insertions, 15 deletions
diff --git a/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs b/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs
index e55e4a5222..225442c215 100644
--- a/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs
+++ b/src/System.Private.CoreLib/shared/System/Text/StringBuilder.cs
@@ -349,7 +349,9 @@ namespace System.Text
}
if (Capacity < capacity)
+ {
Capacity = capacity;
+ }
return Capacity;
}
@@ -610,10 +612,15 @@ namespace System.Text
public bool MoveNext()
{
if (_currentChunk == _firstChunk)
+ {
return false;
+ }
+
if (_manyChunks != null)
+ {
return _manyChunks.MoveNext(ref _currentChunk);
+ }
StringBuilder next = _firstChunk;
while (next.m_ChunkPrevious != _currentChunk)
@@ -657,7 +664,10 @@ namespace System.Text
// the chunks and we can be efficient for large N.
int chunkCount = ChunkCount(stringBuilder);
if (8 < chunkCount)
+ {
_manyChunks = new ManyChunkInfo(stringBuilder, chunkCount);
+ }
+
}
private static int ChunkCount(StringBuilder? stringBuilder)
@@ -683,7 +693,9 @@ namespace System.Text
{
int pos = ++_chunkPos;
if (_chunks.Length <= pos)
+ {
return false;
+ }
current = _chunks[pos];
return true;
}
@@ -816,9 +828,13 @@ namespace System.Text
if (valueLen <= 2)
{
if (valueLen > 0)
+ {
chunkChars[chunkLength] = value[0];
+ }
if (valueLen > 1)
+ {
chunkChars[chunkLength + 1] = value[1];
+ }
}
else
{
@@ -948,7 +964,9 @@ namespace System.Text
private StringBuilder AppendCore(StringBuilder value, int startIndex, int count)
{
if (value == this)
+ {
return Append(value.ToString(startIndex, count));
+ }
int newLength = Length + count;
@@ -1395,7 +1413,9 @@ namespace System.Text
}
if (value != null)
+ {
Insert(index, value, 0, value.Length);
+ }
return this;
}
@@ -1557,17 +1577,23 @@ namespace System.Text
{
// Check next character (if there is one) to see if it is escaped. eg }}
if (pos < len && format[pos] == '}')
+ {
pos++;
+ }
else
+ {
// Otherwise treat it as an error (Mismatched closing brace)
FormatError();
+ }
}
// Is it a opening brace?
if (ch == '{')
{
// Check next character (if there is one) to see if it is escaped. eg {{
if (pos < len && format[pos] == '{')
+ {
pos++;
+ }
else
{
// Otherwise treat it as the opening brace of an Argument Hole.
@@ -1583,7 +1609,10 @@ namespace System.Text
// Start of parsing of Argument Hole.
// Argument Hole ::= { Index (, WS* Alignment WS*)? (: Formatting)? }
//
- if (pos == len) break;
+ if (pos == len)
+ {
+ break;
+ }
//
// Start of parsing required Index parameter.
@@ -1599,14 +1628,20 @@ namespace System.Text
index = index * 10 + ch - '0';
pos++;
// If reached end of text then error (Unexpected end of text)
- if (pos == len) FormatError();
+ if (pos == len)
+ {
+ FormatError();
+ }
ch = format[pos];
// so long as character is digit and value of the index is less than 1000000 ( index limit )
}
while (ch >= '0' && ch <= '9' && index < IndexLimit);
// If value of index is not within the range of the arguments passed in then error (Index out of range)
- if (index >= args.Length) throw new FormatException(SR.Format_IndexOutOfRange);
+ if (index >= args.Length)
+ {
+ throw new FormatException(SR.Format_IndexOutOfRange);
+ }
// Consume optional whitespace.
while (pos < len && (ch = format[pos]) == ' ') pos++;
@@ -1627,7 +1662,10 @@ namespace System.Text
while (pos < len && format[pos] == ' ') pos++;
// If reached the end of the text then error (Unexpected end of text)
- if (pos == len) FormatError();
+ if (pos == len)
+ {
+ FormatError();
+ }
// Is there a minus sign?
ch = format[pos];
@@ -1637,19 +1675,28 @@ namespace System.Text
leftJustify = true;
pos++;
// If reached end of text then error (Unexpected end of text)
- if (pos == len) FormatError();
+ if (pos == len)
+ {
+ FormatError();
+ }
ch = format[pos];
}
// If current character is not a digit then error (Unexpected character)
- if (ch < '0' || ch > '9') FormatError();
+ if (ch < '0' || ch > '9')
+ {
+ FormatError();
+ }
// Parse alignment digits.
do
{
width = width * 10 + ch - '0';
pos++;
// If reached end of text then error. (Unexpected end of text)
- if (pos == len) FormatError();
+ if (pos == len)
+ {
+ FormatError();
+ }
ch = format[pos];
// So long a current character is a digit and the value of width is less than 100000 ( width limit )
}
@@ -1675,7 +1722,10 @@ namespace System.Text
while (true)
{
// If reached end of text then error. (Unexpected end of text)
- if (pos == len) FormatError();
+ if (pos == len)
+ {
+ FormatError();
+ }
ch = format[pos];
if (ch == '}')
@@ -1729,7 +1779,10 @@ namespace System.Text
// Pad the end, if needed.
int padding = width - charsWritten;
- if (leftJustify && padding > 0) Append(' ', padding);
+ if (leftJustify && padding > 0)
+ {
+ Append(' ', padding);
+ }
// Continue to parse other characters.
continue;
@@ -1750,11 +1803,21 @@ namespace System.Text
}
}
// Append it to the final output of the Format String.
- if (s == null) s = string.Empty;
+ if (s == null)
+ {
+ s = string.Empty;
+ }
int pad = width - s.Length;
- if (!leftJustify && pad > 0) Append(' ', pad);
+ if (!leftJustify && pad > 0)
+ {
+ Append(' ', pad);
+ }
+
Append(s);
- if (leftJustify && pad > 0) Append(' ', pad);
+ if (leftJustify && pad > 0)
+ {
+ Append(' ', pad);
+ }
// Continue to parse other characters.
}
return this;
@@ -1778,12 +1841,17 @@ namespace System.Text
public bool Equals(StringBuilder? sb)
{
if (sb == null)
+ {
return false;
+ }
if (Length != sb.Length)
+ {
return false;
+ }
if (sb == this)
+ {
return true;
-
+ }
StringBuilder? thisChunk = this;
int thisChunkIndex = thisChunk.m_ChunkLength;
StringBuilder? sbChunk = sb;
@@ -1797,7 +1865,9 @@ namespace System.Text
{
thisChunk = thisChunk.m_ChunkPrevious;
if (thisChunk == null)
+ {
break;
+ }
thisChunkIndex = thisChunk.m_ChunkLength + thisChunkIndex;
}
@@ -1805,18 +1875,26 @@ namespace System.Text
{
sbChunk = sbChunk.m_ChunkPrevious;
if (sbChunk == null)
+ {
break;
+ }
sbChunkIndex = sbChunk.m_ChunkLength + sbChunkIndex;
}
if (thisChunkIndex < 0)
+ {
return sbChunkIndex < 0;
+ }
if (sbChunkIndex < 0)
+ {
return false;
-
+ }
+
Debug.Assert(thisChunk != null && sbChunk != null);
if (thisChunk.m_ChunkChars[thisChunkIndex] != sbChunk.m_ChunkChars[sbChunkIndex])
+ {
return false;
+ }
}
}
@@ -1827,7 +1905,9 @@ namespace System.Text
public bool Equals(ReadOnlySpan<char> span)
{
if (span.Length != Length)
+ {
return false;
+ }
StringBuilder? sbChunk = this;
int offset = 0;
@@ -1840,7 +1920,9 @@ namespace System.Text
ReadOnlySpan<char> chunk = new ReadOnlySpan<char>(sbChunk.m_ChunkChars, 0, chunk_length);
if (!chunk.EqualsOrdinal(span.Slice(span.Length - offset, chunk_length)))
+ {
return false;
+ }
sbChunk = sbChunk.m_ChunkPrevious;
} while (sbChunk != null);
@@ -1989,7 +2071,9 @@ namespace System.Text
}
}
if (startIndexInChunk >= 0)
+ {
break;
+ }
Debug.Assert(chunk.m_ChunkPrevious != null);
chunk = chunk.m_ChunkPrevious;
@@ -2100,14 +2184,19 @@ namespace System.Text
long longDelta = (value.Length - removeCount) * (long)replacementsCount;
int delta = (int)longDelta;
if (delta != longDelta)
+ {
throw new OutOfMemoryException();
+ }
StringBuilder targetChunk = sourceChunk; // the target as we copy chars down
int targetIndexInChunk = replacements[0];
// Make the room needed for all the new characters if needed.
if (delta > 0)
+ {
MakeRoom(targetChunk.m_ChunkOffset + targetIndexInChunk, delta, out targetChunk, out targetIndexInChunk, true);
+ }
+
// We made certain that characters after the insertion point are not moved,
int i = 0;
for (;;)
@@ -2140,7 +2229,9 @@ namespace System.Text
// Remove extra space if necessary.
if (delta < 0)
+ {
Remove(targetChunk.m_ChunkOffset + targetIndexInChunk, -delta, out targetChunk, out targetIndexInChunk);
+ }
}
}
}
@@ -2165,7 +2256,9 @@ namespace System.Text
{
chunk = Next(chunk)!;
if (chunk == null)
+ {
return false;
+ }
indexInChunk = 0;
}
@@ -2354,8 +2447,10 @@ namespace System.Text
// Check for integer overflow (logical buffer size > int.MaxValue)
if (m_ChunkOffset + m_ChunkLength + newBlockLength < newBlockLength)
+ {
throw new OutOfMemoryException();
-
+ }
+
// Allocate the array before updating any state to avoid leaving inconsistent state behind in case of out of memory exception
char[] chunkChars = new char[newBlockLength];