Skip to content

Commit decf49f

Browse files
committed
StyleCop warnings fixed for consistency
1 parent 820e1aa commit decf49f

File tree

11 files changed

+1260
-1038
lines changed

11 files changed

+1260
-1038
lines changed

Source/GenCode128/AssemblyInfo.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
using System.Reflection;
2-
using System.Runtime.CompilerServices;
32

4-
//
53
// General Information about an assembly is controlled through the following
64
// set of attributes. Change these attribute values to modify the information
75
// associated with an assembly.
8-
//
96
[assembly: AssemblyTitle("GenCode128")]
107
[assembly: AssemblyDescription("GenCode128")]
118
[assembly: AssemblyConfiguration("")]
129
[assembly: AssemblyCompany("Chris Wuestefeld")]
1310
[assembly: AssemblyProduct("")]
1411
[assembly: AssemblyCopyright("2006 Chris Wuestefeld")]
1512
[assembly: AssemblyTrademark("")]
16-
[assembly: AssemblyCulture("")]
13+
[assembly: AssemblyCulture("")]
1714

18-
//
1915
// Version information for an assembly consists of the following four values:
2016
//
2117
// Major Version
@@ -25,10 +21,8 @@
2521
//
2622
// You can specify all the values or you can default the Revision and Build Numbers
2723
// by using the '*' as shown below:
28-
2924
[assembly: AssemblyVersion("1.0.0.0")]
3025

31-
//
3226
// In order to sign your assembly you must specify a key to use. Refer to the
3327
// Microsoft .NET Framework documentation for more information on assembly signing.
3428
//
@@ -52,7 +46,6 @@
5246
// attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
5347
// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
5448
// documentation for more information on this.
55-
//
5649
[assembly: AssemblyDelaySign(false)]
5750
[assembly: AssemblyKeyFile("")]
5851
[assembly: AssemblyKeyName("")]

Source/GenCode128/Code128Code.cs

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
namespace GenCode128
2+
{
3+
/// <summary>
4+
/// Static tools for determining codes for individual characters in the content
5+
/// </summary>
6+
public static class Code128Code
7+
{
8+
private const int CShift = 98;
9+
10+
private const int CCodeA = 101;
11+
12+
private const int CCodeB = 100;
13+
14+
private const int CStartA = 103;
15+
16+
private const int CStartB = 104;
17+
18+
private const int CStop = 106;
19+
20+
/// <summary>
21+
/// Indicates which code sets can represent a character -- CodeA, CodeB, or either
22+
/// </summary>
23+
public enum CodeSetAllowed
24+
{
25+
CodeA,
26+
27+
CodeB,
28+
29+
CodeAorB
30+
}
31+
32+
/// <summary>
33+
/// Get the Code128 code value(s) to represent an ASCII character, with
34+
/// optional look-ahead for length optimization
35+
/// </summary>
36+
/// <param name="charAscii">The ASCII value of the character to translate</param>
37+
/// <param name="lookAheadAscii">The next character in sequence (or -1 if none)</param>
38+
/// <param name="currCodeSet">The current codeset, that the returned codes need to follow;
39+
/// if the returned codes change that, then this value will be changed to reflect it</param>
40+
/// <returns>An array of integers representing the codes that need to be output to produce the
41+
/// given character</returns>
42+
public static int[] CodesForChar(int charAscii, int lookAheadAscii, ref CodeSet currCodeSet)
43+
{
44+
int[] result;
45+
int shifter = -1;
46+
47+
if (!CharCompatibleWithCodeset(charAscii, currCodeSet))
48+
{
49+
// if we have a lookahead character AND if the next character is ALSO not compatible
50+
if ((lookAheadAscii != -1) && !CharCompatibleWithCodeset(lookAheadAscii, currCodeSet))
51+
{
52+
// we need to switch code sets
53+
switch (currCodeSet)
54+
{
55+
case CodeSet.CodeA:
56+
shifter = CCodeB;
57+
currCodeSet = CodeSet.CodeB;
58+
break;
59+
case CodeSet.CodeB:
60+
shifter = CCodeA;
61+
currCodeSet = CodeSet.CodeA;
62+
break;
63+
}
64+
}
65+
else
66+
{
67+
// no need to switch code sets, a temporary SHIFT will suffice
68+
shifter = CShift;
69+
}
70+
}
71+
72+
if (shifter != -1)
73+
{
74+
result = new int[2];
75+
result[0] = shifter;
76+
result[1] = CodeValueForChar(charAscii);
77+
}
78+
else
79+
{
80+
result = new int[1];
81+
result[0] = CodeValueForChar(charAscii);
82+
}
83+
84+
return result;
85+
}
86+
87+
/// <summary>
88+
/// Tells us which codesets a given character value is allowed in
89+
/// </summary>
90+
/// <param name="charAscii">ASCII value of character to look at</param>
91+
/// <returns>Which codeset(s) can be used to represent this character</returns>
92+
public static CodeSetAllowed CodesetAllowedForChar(int charAscii)
93+
{
94+
if (charAscii >= 32 && charAscii <= 95)
95+
{
96+
return CodeSetAllowed.CodeAorB;
97+
}
98+
else
99+
{
100+
return (charAscii < 32) ? CodeSetAllowed.CodeA : CodeSetAllowed.CodeB;
101+
}
102+
}
103+
104+
/// <summary>
105+
/// Determine if a character can be represented in a given codeset
106+
/// </summary>
107+
/// <param name="charAscii">character to check for</param>
108+
/// <param name="currcs">codeset context to test</param>
109+
/// <returns>true if the codeset contains a representation for the ASCII character</returns>
110+
public static bool CharCompatibleWithCodeset(int charAscii, CodeSet currcs)
111+
{
112+
CodeSetAllowed csa = CodesetAllowedForChar(charAscii);
113+
return csa == CodeSetAllowed.CodeAorB || (csa == CodeSetAllowed.CodeA && currcs == CodeSet.CodeA)
114+
|| (csa == CodeSetAllowed.CodeB && currcs == CodeSet.CodeB);
115+
}
116+
117+
/// <summary>
118+
/// Gets the integer code128 code value for a character (assuming the appropriate code set)
119+
/// </summary>
120+
/// <param name="charAscii">character to convert</param>
121+
/// <returns>code128 symbol value for the character</returns>
122+
public static int CodeValueForChar(int charAscii)
123+
{
124+
return (charAscii >= 32) ? charAscii - 32 : charAscii + 64;
125+
}
126+
127+
/// <summary>
128+
/// Return the appropriate START code depending on the codeset we want to be in
129+
/// </summary>
130+
/// <param name="cs">The codeset you want to start in</param>
131+
/// <returns>The code128 code to start a barcode in that codeset</returns>
132+
public static int StartCodeForCodeSet(CodeSet cs)
133+
{
134+
return cs == CodeSet.CodeA ? CStartA : CStartB;
135+
}
136+
137+
/// <summary>
138+
/// Return the Code128 stop code
139+
/// </summary>
140+
/// <returns>the stop code</returns>
141+
public static int StopCode()
142+
{
143+
return CStop;
144+
}
145+
}
146+
}

0 commit comments

Comments
 (0)