You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ZXAI01weightDecoder.m 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright 2012 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 "ZXAI01weightDecoder.h"
  17. #import "ZXRSSExpandedGeneralAppIdDecoder.h"
  18. @implementation ZXAI01weightDecoder
  19. - (void)encodeCompressedWeight:(NSMutableString *)buf currentPos:(int)currentPos weightSize:(int)weightSize {
  20. int originalWeightNumeric = [self.generalDecoder extractNumericValueFromBitArray:currentPos bits:weightSize];
  21. [self addWeightCode:buf weight:originalWeightNumeric];
  22. int weightNumeric = [self checkWeight:originalWeightNumeric];
  23. int currentDivisor = 100000;
  24. for (int i = 0; i < 5; ++i) {
  25. if (weightNumeric / currentDivisor == 0) {
  26. [buf appendString:@"0"];
  27. }
  28. currentDivisor /= 10;
  29. }
  30. [buf appendFormat:@"%d", weightNumeric];
  31. }
  32. - (void)addWeightCode:(NSMutableString *)buf weight:(int)weight {
  33. @throw [NSException exceptionWithName:NSInternalInconsistencyException
  34. reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]
  35. userInfo:nil];
  36. }
  37. - (int)checkWeight:(int)weight {
  38. @throw [NSException exceptionWithName:NSInternalInconsistencyException
  39. reason:[NSString stringWithFormat:@"You must override %@ in a subclass", NSStringFromSelector(_cmd)]
  40. userInfo:nil];
  41. }
  42. @end