Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright 2014 ZXing authors
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "ZXByteArray.h"
  17. @implementation ZXByteArray
  18. - (id)initWithLength:(unsigned int)length {
  19. if (self = [super init]) {
  20. if (length > 0) {
  21. _array = (int8_t *)calloc(length, sizeof(int8_t));
  22. } else {
  23. _array = NULL;
  24. }
  25. _length = length;
  26. }
  27. return self;
  28. }
  29. - (id)initWithBytes:(int)byte1, ... {
  30. va_list args;
  31. va_start(args, byte1);
  32. unsigned int length = 0;
  33. for (int8_t byte = byte1; byte != -1; byte = va_arg(args, int)) {
  34. length++;
  35. }
  36. va_end(args);
  37. if ((self = [self initWithLength:length]) && (length > 0)) {
  38. va_list args;
  39. va_start(args, byte1);
  40. int i = 0;
  41. for (int8_t byte = byte1; byte != -1; byte = va_arg(args, int)) {
  42. _array[i++] = byte;
  43. }
  44. va_end(args);
  45. }
  46. return self;
  47. }
  48. - (void)dealloc {
  49. if (_array) {
  50. free(_array);
  51. }
  52. }
  53. - (NSString *)description {
  54. NSMutableString *s = [NSMutableString stringWithFormat:@"length=%u, array=(", self.length];
  55. for (int i = 0; i < self.length; i++) {
  56. [s appendFormat:@"%hhx", self.array[i]];
  57. if (i < self.length - 1) {
  58. [s appendString:@", "];
  59. }
  60. }
  61. [s appendString:@")"];
  62. return s;
  63. }
  64. @end