This repository has been archived by the owner on Sep 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
/
NKDCode128Barcode.m
executable file
·892 lines (875 loc) · 22.3 KB
/
NKDCode128Barcode.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
// -----------------------------------------------------------------------------------
// NKDCode128Barcode.m
// -----------------------------------------------------------------------------------
// Created by Jeff LaMarche on Sat May 11 2002.
// �2002 Naked Software. All rights reserved.
// -----------------------------------------------------------------------------------
// THIS SOURCE CODE IS PROVIDED AS-IS WITH NO WARRANTY OF ANY KIND
// -----------------------------------------------------------------------------------
// You may use and redistribute this source code without limitation
// -----------------------------------------------------------------------------------
#import "NKDCode128Barcode.h"
@implementation NKDCode128Barcode
// -----------------------------------------------------------------------------------
-(id)initWithContent: (NSString *)inContent
printsCaption: (BOOL)inPrints
// -----------------------------------------------------------------------------------
{
self = [super initWithContent:inContent printsCaption:inPrints];
if (self)
{
[self setCodeSet:[self _bestCodeSetForContent]];
[self generateChecksum];
[self calculateWidth];
}
return self;
}
// -----------------------------------------------------------------------------------
-(CodeSet)codeSet
// -----------------------------------------------------------------------------------
{
return codeSet;
}
// -----------------------------------------------------------------------------------
-(void)setCodeSet:(CodeSet)inSet
// -----------------------------------------------------------------------------------
{
codeSet = inSet;
}
// -----------------------------------------------------------------------------------
-(void)generateChecksum
// -----------------------------------------------------------------------------------
{
int startCode=0, sum=0;
char *code = (char *)[[self content] cStringUsingEncoding:NSStringEncodingConversionAllowLossy];
switch (codeSet)
{
case SET_A:
startCode = 103;
break;
case SET_B:
startCode = 104;
break;
case SET_C:
startCode = 105;
break;
}
sum += startCode;
int codeLen = strlen(code);
if (codeSet != SET_C)
for (int i=0, j = 1; i < codeLen; i++, j++)
sum += j * [self _valueForChar:code[i]];
else { // SET_C
if(codeLen % 2 != 0){
code = (char *)[[NSString stringWithFormat:@"0%@", [self content]] cStringUsingEncoding:NSStringEncodingConversionAllowLossy];
codeLen ++;
}
for (int i=0, j = 1; i < codeLen; i+=2, j++){
NSString * pair = [NSString stringWithFormat:@"%c%c", code[i], code[i+1]];
sum += j * [pair intValue];
}
}
checkDigit = (char)(sum%103);
}
// -----------------------------------------------------------------------------------
-(int)_valueForChar:(int)inChar
// -----------------------------------------------------------------------------------
{
if(inChar == 128){
return 0;
} else if(inChar >= 33 && inChar <= 126){
return inChar - 32;
} else if(inChar > 126){
return inChar - 50;
}
// If it gets here, error condition...
NSLog(@"_valueForChar: received Unrecognized character %c", inChar);
return -1;
}
-(int)_charForValue:(int)inValue
{
if(inValue == 0){
return 128;
} else if(inValue >= 1 && inValue <= 94){
return inValue + 32;
} else if(inValue > 94){
return inValue + 50;
}
NSLog(@"_charForValue: received Unrecognized value %i", inValue);
return -1;
}
// -----------------------------------------------------------------------------------
-(NSString *)initiator
// -----------------------------------------------------------------------------------
{
switch (codeSet)
{
case SET_A:
return @"11010000100";
case SET_B:
return @"11010010000";
case SET_C:
return @"11010011100";
default:
NSLog(@"Invalid codeSet value: %c", codeSet);
}
return @"";
}
// -----------------------------------------------------------------------------------
-(NSString *)terminator
// -----------------------------------------------------------------------------------
{
return @"1100011101011";
}
// -----------------------------------------------------------------------------------
-(NSString *)_encodeChar:(char)inChar
// -----------------------------------------------------------------------------------
{
int useSet = codeSet; // Specifies the code on a per-character basis;
NSString *prefix;
// *** We currently only switch from A to B and vice versa
if (![self _canEncodeChar:inChar withSet:codeSet])
{
useSet = (codeSet == SET_A) ? SET_B : SET_A;
prefix = [self _shiftCharacterForSet:useSet];
}
else
prefix = @"";
return [NSString stringWithFormat:@"%@%@",prefix, [self _encodeChar:inChar withSet:codeSet]];
}
// -----------------------------------------------------------------------------------
-(BOOL)_canEncodeChar:(char)inChar withSet:(CodeSet)theSet
// -----------------------------------------------------------------------------------
{
return (![[self _encodeChar:inChar withSet:theSet] isEqual:@""]);
}
// -----------------------------------------------------------------------------------
-(NSString *)_encodeChar:(char)inChar withSet:(CodeSet)inSet
// -----------------------------------------------------------------------------------
{
// SET_A and SET_B have a lot of characters in common, SET_C uses a
// separate encoding method.
if(inSet == SET_B) {
switch (inChar) {
case ' ':
return @"11011001100";
case '!':
return @"11001101100";
case '"':
return @"11001100110";
case '#':
return @"10010011000";
case '$':
return @"10010001100";
case '%':
return @"10001001100";
case '&':
return @"10011001000";
case '\'':
return @"10011000100";
case '(':
return @"10001100100";
case ')':
return @"11001001000";
case '*':
return @"11001000100";
case '+':
return @"11000100100";
case ',':
return @"10110011100";
case '-':
return @"10011011100";
case '.':
return @"10011001110";
case '/':
return @"10111001100";
case '0':
return @"10011101100";
case '1':
return @"10011100110";
case '2':
return @"11001110010";
case '3':
return @"11001011100";
case '4':
return @"11001001110";
case '5':
return @"11011100100";
case '6':
return @"11001110100";
case '7':
return @"11101101110";
case '8':
return @"11101001100";
case '9':
return @"11100101100";
case ':':
return @"11100100110";
case ';':
return @"11101100100";
case '<':
return @"11100110100";
case '=':
return @"11100110010";
case '>':
return @"11011011000";
case '?':
return @"11011000110";
case '@':
return @"11000110110";
case 'A':
return @"10100011000";
case 'B':
return @"10001011000";
case 'C':
return @"10001000110";
case 'D':
return @"10110001000";
case 'E':
return @"10001101000";
case 'F':
return @"10001100010";
case 'G':
return @"11010001000";
case 'H':
return @"11000101000";
case 'I':
return @"11000100010";
case 'J':
return @"10110111000";
case 'K':
return @"10110001110";
case 'L':
return @"10001101110";
case 'M':
return @"10111011000";
case 'N':
return @"10111000110";
case 'O':
return @"10001110110";
case 'P':
return @"11101110110";
case 'Q':
return @"11010001110";
case 'R':
return @"11000101110";
case 'S':
return @"11011101000";
case 'T':
return @"11011100010";
case 'U':
return @"11011101110";
case 'V':
return @"11101011000";
case 'W':
return @"11101000110";
case 'X':
return @"11100010110";
case 'Y':
return @"11101101000";
case 'Z':
return @"11101100010";
case '[':
return @"11100011010";
case '\\':
return @"11101111010";
case ']':
return @"11001000010";
case '^':
return @"11110001010";
case '_':
return @"10100110000";
case '`':
return @"10100001100";
case 'a':
return @"10010110000";
case 'b':
return @"10010000110";
case 'c':
return @"10000101100";
case 'd':
return @"10000100110";
case 'e':
return @"10110010000";
case 'f':
return @"10110000100";
case 'g':
return @"10011010000";
case 'h':
return @"10011000010";
case 'i':
return @"10000110100";
case 'j':
return @"10000110010";
case 'k':
return @"11000010010";
case 'l':
return @"11001010000";
case 'm':
return @"11110111010";
case 'n':
return @"11000010100";
case 'o':
return @"10001111010";
case 'p':
return @"10100111100";
case 'q':
return @"10010111100";
case 'r':
return @"10010011110";
case 's':
return @"10111100100";
case 't':
return @"10011110100";
case 'u':
return @"10011110010";
case 'v':
return @"11110100100";
case 'w':
return @"11110010100";
case 'x':
return @"11110010010";
case 'y':
return @"11011011110";
case 'z':
return @"11011110110";
case '{':
return @"11110110110";
case '|':
return @"10101111000";
case '}':
return @"10100011110";
case '~':
return @"10001011110";
}
} else {
switch(inChar)
{
case ' ':
return @"11011001100";
case '!':
return @"11001101100";
case '"':
return @"11001100110";
case '#':
return @"10010011000";
case '$':
return @"10010001100";
case '%':
return @"10001001100";
case '&':
return @"10011001000";
case '\'':
return @"10011000100";
case '(':
return @"10001100100";
case ')':
return @"11001001000";
case '*':
return @"11001000100";
case '+':
return @"11000100100";
case ',':
return @"10110011100";
case '-':
return @"10011011100";
case '.':
return @"10011001110";
case '/':
return @"10111001100";
case '0':
return @"10011101100";
case '1':
return @"10011100110";
case '2':
return @"11001110010";
case '3':
return @"11001011100";
case '4':
return @"11001001110";
case '5':
return @"11011100100";
case '6':
return @"11001110100";
case '7':
return @"11101101110";
case '8':
return @"11101001100";
case '9':
return @"11100101100";
case ':':
return @"11100100110";
case '<':
return @"11100110100";
case '=':
return @"11100110010";
case '>':
return @"11011011000";
case '?':
return @"11011000110";
case '@':
return @"11000110110";
case 'A':
return @"10100011000";
case 'B':
return @"10001011000";
case 'C':
return @"10001000110";
case 'D':
return @"10110001000";
case 'E':
return @"10001101000";
case 'F':
return @"10001100010";
case 'G':
return @"11010001000";
case 'H':
return @"11000101000";
case 'I':
return @"11000100010";
case 'J':
return @"10110111000";
case 'K':
return @"10110001110";
case 'L':
return @"10001101110";
case 'M':
return @"10111011000";
case 'N':
return @"10111000110";
case 'O':
return @"10001110110";
case 'P':
return @"11101110110";
case 'Q':
return @"11010001110";
case 'R':
return @"11000101110";
case 'S':
return @"11011101000";
case 'T':
return @"11011100010";
case 'U':
return @"11011101110";
case 'V':
return @"11101011000";
case 'W':
return @"11101000110";
case 'X':
return @"11100010110";
case 'Y':
return @"11101101000";
case 'Z':
return @"11101100010";
case '[':
return @"11100011010";
case '\\':
return @"11101111010";
case ']':
return @"11001000010";
case '^':
return @"11110001010";
case '_':
return @"10100110000";
case '`':
return (inSet == SET_B) ? @"10100001100" : @"";
case 0: // NUL
return (inSet == SET_A) ? @"10100001100" : @"";
case 'a':
return (inSet == SET_B) ? @"10010110000" : @"";
case 1: // SOH
return (inSet == SET_A) ? @"10010110000" : @"";
case 'b':
return (inSet == SET_B) ? @"10010000110" : @"";
case 2: // STX
return (inSet == SET_A) ? @"10010000110" : @"";
case 'c':
return (inSet == SET_B) ? @"10000101100" : @"";
case 3: // ETX
return (inSet == SET_A) ? @"10000101100" : @"";
case 'd':
return (inSet == SET_B) ? @"10000100110" : @"";
case 4: // EOT
return (inSet == SET_A) ? @"10000100110" : @"";
case 'e':
return (inSet == SET_B) ? @"10110010000" : @"";
case 5: // ENQ
return (inSet == SET_A) ? @"10110010000" : @"";
case 'f':
return (inSet == SET_B) ? @"10110000100" : @"";
case 6: // ACK
return (inSet == SET_A) ? @"10110000100" : @"";
case 'g':
return (inSet == SET_B) ? @"10011010000" : @"";
case 7: // BEL
return (inSet == SET_A) ? @"10011010000" : @"";
case 'h':
return (inSet == SET_B) ? @"10011000010" : @"";
case 8: // BS
return (inSet == SET_A) ? @"10011000010" : @"";
case 'i':
return (inSet == SET_B) ? @"10000110100" : @"";
case 9: // HT
return (inSet == SET_A) ? @"10000110100" : @"";
case 'j':
return (inSet == SET_B) ? @"10000110010" : @"";
case 10: // LF
return (inSet == SET_A) ? @"10000110010" : @"";
case 'k':
return (inSet == SET_B) ? @"11000010010" : @"";
case 11: // VT
return (inSet == SET_A) ? @"11000010010" : @"";
case 'l':
return (inSet == SET_B) ? @"11001010000" : @"";
case 12: // FF
return (inSet == SET_A) ? @"11001010000" : @"";
case 'm':
return (inSet == SET_B) ? @"11110111010" : @"";
case 13: // CR
return (inSet == SET_A) ? @"11110111010" : @"";
case 'n':
return (inSet == SET_B) ? @"11000010100" : @"";
case 14: // SO
return (inSet == SET_A) ? @"11000010100" : @"";
case 'o':
return (inSet == SET_B) ? @"10001111010" : @"";
case 15: // SI
return (inSet == SET_A) ? @"10001111010" : @"";
case 'p':
return (inSet == SET_B) ? @"10100111100" : @"";
case 16: // DLE
return (inSet == SET_A) ? @"10100111100" : @"";
case 'q':
return (inSet == SET_B) ? @"10010111100" : @"";
case 17: // DC1
return (inSet == SET_A) ? @"10010111100" : @"";
case 'r':
return (inSet == SET_B) ? @"10010011110" : @"";
case 18: // DC2
return (inSet == SET_A) ? @"10010011110" : @"";
case 's':
return (inSet == SET_B) ? @"10111100100" : @"";
case 19: // DC3
return (inSet == SET_A) ? @"10111100100" : @"";
case 't':
return (inSet == SET_B) ? @"10111100100" : @"";
case 20: // DC4
return (inSet == SET_A) ? @"10111100100" : @"";
case 'u':
return (inSet == SET_B) ? @"10011110010" : @"";
case 21: // NAK
return (inSet == SET_A) ? @"10011110010" : @"";
case 'v':
return (inSet == SET_B) ? @"11110100100" : @"";
case 22: // SYN
return (inSet == SET_A) ? @"11110100100" : @"";
case 'w':
return (inSet == SET_B) ? @"11110010100" : @"";
case 23: // ETB
return (inSet == SET_A) ? @"11110010100" : @"";
case 'x':
return (inSet == SET_B) ? @"11110010010" : @"";
case 24: // CAN
return (inSet == SET_A) ? @"11110010010" : @"";
case 'y':
return (inSet == SET_B) ? @"11011011110" : @"";
case 25: // EM
return (inSet == SET_A) ? @"11011011110" : @"";
case 'z':
return (inSet == SET_B) ? @"11011110110" : @"";
case 26: // SUB
return (inSet == SET_A) ? @"11011110110" : @"";
case '{':
return (inSet == SET_B) ? @"11110110110" : @"";
case 27: // ESC
return (inSet == SET_A) ? @"11110110110" : @"";
case '|':
return (inSet == SET_B) ? @"10101111000" : @"";
case 28: // FS
return (inSet == SET_A) ? @"10101111000" : @"";
case '}':
return (inSet == SET_B) ? @"10100011110" : @"";
case 29: // GS
return (inSet == SET_A) ? @"10100011110" : @"";
}
}
return @"";
}
// -----------------------------------------------------------------------------------
-(CodeSet)_bestCodeSetForContent
// -----------------------------------------------------------------------------------
{
int numNumbers = 0,
numNonPrinting = 0,
numLowerCase = 0,
i;
char *code = (char *)[[self content] cStringUsingEncoding:NSStringEncodingConversionAllowLossy];
for (i=0; i < strlen(code); i++)
{
if ((code[i] >= '0') && (code[i] <= '9'))
numNumbers++;
else if ((code[i] < 32) || (code[i] == 127))
numNonPrinting++;
else if ((code[i] >= 'a') && (code[i] <= 'z'))
numLowerCase++;
}
if (numNumbers == strlen(code))
return SET_C;
return (numNonPrinting > numLowerCase) ? SET_A : SET_B;
}
// -----------------------------------------------------------------------------------
-(NSString *)_shiftCharacterForSet:(CodeSet)inSet
// -----------------------------------------------------------------------------------
{
switch (inSet)
{
case SET_A:
return @"1111010001011101011110";
case SET_B:
return @"1111010001010111101110";
case SET_C:
return @"1111010001010111011110";
default:
NSLog(@"Invalid CodeSet value Supplied: %c", inSet);
}
return @"";
}
// -----------------------------------------------------------------------------------
-(NSString *)_encodeNumberPair:(NSString *)inPair
// -----------------------------------------------------------------------------------
{
int pair = [inPair intValue];
switch (pair)
{
case 0:
return @"11011001100";
case 1:
return @"11001101100";
case 2:
return @"11001100110";
case 3:
return @"10010011000";
case 4:
return @"10010001100";
case 5:
return @"10001001100";
case 6:
return @"10011001000";
case 7:
return @"10011000100";
case 8:
return @"10001100100";
case 9:
return @"11001001000";
case 10:
return @"11001000100";
case 11:
return @"11000100100";
case 12:
return @"10110011100";
case 13:
return @"10011011100";
case 14:
return @"10011001110";
case 15:
return @"10111001100";
case 16:
return @"10011101100";
case 17:
return @"10011100110";
case 18:
return @"11001110010";
case 19:
return @"11001011100";
case 20:
return @"11001001110";
case 21:
return @"11011100100";
case 22:
return @"11001110100";
case 23:
return @"11101101110";
case 24:
return @"11101001100";
case 25:
return @"11100101100";
case 26:
return @"11100100110";
case 27:
return @"11101100100";
case 28:
return @"11100110100";
case 29:
return @"11100110010";
case 30:
return @"11011011000";
case 31:
return @"11011000110";
case 32:
return @"11000110110";
case 33:
return @"10100011000";
case 34:
return @"10001011000";
case 35:
return @"10001000110";
case 36:
return @"10110001000";
case 37:
return @"10001101000";
case 38:
return @"10001100010";
case 39:
return @"11010001000";
case 40:
return @"11000101000";
case 41:
return @"11000100010";
case 42:
return @"10110111000";
case 43:
return @"10110001110";
case 44:
return @"10001101110";
case 45:
return @"10111011000";
case 46:
return @"10111000110";
case 47:
return @"10001110110";
case 48:
return @"11101110110";
case 49:
return @"11010001110";
case 50:
return @"11000101110";
case 51:
return @"11011101000";
case 52:
return @"11011100010";
case 53:
return @"11011101110";
case 54:
return @"11101011000";
case 55:
return @"11101000110";
case 56:
return @"11100010110";
case 57:
return @"11101101000";
case 58:
return @"11101100010";
case 59:
return @"11100011010";
case 60:
return @"11101111010";
case 61:
return @"11001000010";
case 62:
return @"11110001010";
case 63:
return @"10100110000";
case 64:
return @"10100001100";
case 65:
return @"10010110000";
case 66:
return @"10010000110";
case 67:
return @"10000101100";
case 68:
return @"10000100110";
case 69:
return @"10110010000";
case 70:
return @"10110000100";
case 71:
return @"10011010000";
case 72:
return @"10011000010";
case 73:
return @"10000110100";
case 74:
return @"10000110010";
case 75:
return @"11000010010";
case 76:
return @"11001010000";
case 77:
return @"11110111010";
case 78:
return @"11000010100";
case 79:
return @"10001111010";
case 80:
return @"10100111100";
case 81:
return @"10010111100";
case 82:
return @"10010011110";
case 83:
return @"10111100100";
case 84:
return @"10011110100";
case 85:
return @"10011110010";
case 86:
return @"11110100100";
case 87:
return @"11110010100";
case 88:
return @"11110010010";
case 89:
return @"11011011110";
case 90:
return @"11011110110";
case 91:
return @"11110110110";
case 92:
return @"10101111000";
case 93:
return @"10100011110";
case 94:
return @"10001011110";
case 95:
return @"10111101000";
case 96:
return @"10111100010";
case 97:
return @"11110101000";
case 98:
return @"11110100010";
case 99:
return @"10111011110";
case 100:
return @"10111101110";
case 101:
return @"11101011110";
case 102:
return @"11110101110";
}
return @"";
}
// -----------------------------------------------------------------------------------
-(NSString *)barcode
// -----------------------------------------------------------------------------------
{
NSMutableString *theReturn = [NSMutableString stringWithString:@""];
char * code = (char *)[[self content] cStringUsingEncoding:NSStringEncodingConversionAllowLossy];
int i;
if (codeSet == SET_C)
{
// Left-pad with zero if odd number of characters
if (strlen(code)%2 != 0)
code = (char *)[[NSString stringWithFormat:@"0%@",[NSString stringWithCString:code encoding:NSStringEncodingConversionAllowLossy]] cStringUsingEncoding:NSStringEncodingConversionAllowLossy];
// Encode character pairs
for (i=0; i < strlen(code); i+=2)
[theReturn appendString:[self _encodeNumberPair:[NSString stringWithFormat:@"%c%c", code[i], code[i+1]]]];
}
else
for (i=0; i < strlen(code); i++)
[theReturn appendString:[self _encodeChar:code[i]]];
[theReturn appendString:[self _encodeNumberPair:[[NSNumber numberWithInt:(int)checkDigit] stringValue]]];
return theReturn;
}
@end