// Decode the supplied Whynter message. // // Args: // results: Ptr to the data to decode and where to store the decode result. // nbits: Nr. of data bits to expect. // strict: Flag indicating if we should perform strict matching. // Returns: // boolean: True if it can decode it, false if it can't. // // Status: BETA Strict mode is ALPHA. // // Ref: // https://github.com/z3t0/Arduino-IRremote/blob/master/ir_Whynter.cpp bool IRrecv::decodeWhynter(decode_results *results, uint16_t nbits, bool strict) { if (results->rawlen < 2 * nbits + 2 * HEADER + FOOTER - 1) return false; // We don't have enough entries to possibly match. // Compliance if (strict && nbits != WHYNTER_BITS) return false; // Incorrect nr. of bits per spec. uint16_t offset = OFFSET_START; // Header // Sequence begins with a bit mark and a zero space. // These are typically small, so we'll prefer to do the calibration // on the much larger header mark & space that are next. if (!matchMark(results->rawbuf[offset++], WHYNTER_BIT_MARK)) return false; if (!matchSpace(results->rawbuf[offset++], WHYNTER_ZERO_SPACE)) return false; // Main header mark and space if (!matchMark(results->rawbuf[offset], WHYNTER_HDR_MARK)) return false; // Calculate how long the common tick time is based on the header mark. uint32_t m_tick = results->rawbuf[offset++] * RAWTICK / WHYNTER_HDR_MARK_TICKS; if (!matchSpace(results->rawbuf[offset], WHYNTER_HDR_SPACE)) return false; // Calculate how long the common tick time is based on the header space. uint32_t s_tick = results->rawbuf[offset++] * RAWTICK / WHYNTER_HDR_SPACE_TICKS; // Data uint64_t data = 0; match_result_t data_result = matchData(&(results->rawbuf[offset]), nbits, WHYNTER_BIT_MARK_TICKS * m_tick, WHYNTER_ONE_SPACE_TICKS * s_tick, WHYNTER_BIT_MARK_TICKS * m_tick, WHYNTER_ZERO_SPACE_TICKS * s_tick); if (data_result.success == false) return false; data = data_result.data; offset += data_result.used; // Footer if (!matchMark(results->rawbuf[offset++], WHYNTER_BIT_MARK_TICKS * m_tick)) return false; if (offset < results->rawlen && !matchAtLeast(results->rawbuf[offset], WHYNTER_MIN_GAP_TICKS * s_tick)) return false; // Success results->decode_type = WHYNTER; results->bits = nbits; results->value = data; results->address = 0; results->command = 0; return true; }
// Decode the supplied Whynter message. // // Args: // results: Ptr to the data to decode and where to store the decode result. // nbits: Nr. of data bits to expect. // strict: Flag indicating if we should perform strict matching. // Returns: // boolean: True if it can decode it, false if it can't. // // Status: BETA Strict mode is ALPHA. // // Ref: // https://github.com/z3t0/Arduino-IRremote/blob/master/ir_Whynter.cpp bool IRrecv::decodeWhynter(decode_results *results, uint16_t nbits, bool strict) { if (results->rawlen < 2 * nbits + 2 * kHeader + kFooter - 1) return false; // We don't have enough entries to possibly match. // Compliance if (strict && nbits != kWhynterBits) return false; // Incorrect nr. of bits per spec. uint16_t offset = kStartOffset; // Header // Sequence begins with a bit mark and a zero space. // These are typically small, so we'll prefer to do the calibration // on the much larger header mark & space that are next. if (!matchMark(results->rawbuf[offset++], kWhynterBitMark)) return false; if (!matchSpace(results->rawbuf[offset++], kWhynterZeroSpace)) return false; // Main header mark and space if (!matchMark(results->rawbuf[offset], kWhynterHdrMark)) return false; // Calculate how long the common tick time is based on the header mark. uint32_t m_tick = results->rawbuf[offset++] * kRawTick / kWhynterHdrMarkTicks; if (!matchSpace(results->rawbuf[offset], kWhynterHdrSpace)) return false; // Calculate how long the common tick time is based on the header space. uint32_t s_tick = results->rawbuf[offset++] * kRawTick / kWhynterHdrSpaceTicks; // Data uint64_t data = 0; match_result_t data_result = matchData(&(results->rawbuf[offset]), nbits, kWhynterBitMarkTicks * m_tick, kWhynterOneSpaceTicks * s_tick, kWhynterBitMarkTicks * m_tick, kWhynterZeroSpaceTicks * s_tick); if (data_result.success == false) return false; data = data_result.data; offset += data_result.used; // Footer if (!matchMark(results->rawbuf[offset++], kWhynterBitMarkTicks * m_tick)) return false; if (offset < results->rawlen && !matchAtLeast(results->rawbuf[offset], kWhynterMinGapTicks * s_tick)) return false; // Success results->decode_type = WHYNTER; results->bits = nbits; results->value = data; results->address = 0; results->command = 0; return true; }
bool Regex::match(const std::string& str, RegexMatch& matchObject) { ScopedMatchData matchData(mPCRE); const size_t numMatches = matchData.match(str); matchObject.resize(numMatches); if (numMatches == 0) { return false; } for (size_t ii = 0; ii < numMatches; ++ii) { matchObject[ii] = matchData.getMatch(str, ii); } return true; }
std::string Regex::search(const std::string& matchString, size_t startIndex, sys::Uint32_T flags, size_t& begin, size_t& end) { ScopedMatchData matchData(mPCRE); const size_t numMatches = matchData.match(matchString, startIndex, flags); if (numMatches > 0) { begin = matchData.getOutputVector()[0]; end = matchData.getOutputVector()[1]; return matchData.getMatch(matchString, 0); } else { begin = end = 0; return ""; } }
/** * Questa funzione legge e scrive un'agenda effettuando controlli * necessari a verificare che il file sia stato formattato correttamente * e che la conversione sia corretta * * \param fagenda nome del file agenda * \param ftest nome del file in cui verranno scritte le voci covertite */ void run_testagenda (char *fagenda, char* ftest) { char record[LRECORD+2], pbu[MAXNTEST][LRECORD+1], pb[LRECORD+1]; evento_t* ev[MAXNTEST]; FILE *fsa; /* prossima posizione libera nell'array di eventi */ int i=0; int l,k; /* * Apertura del file agenda */ fsa = fopen(fagenda, "r"); CU_ASSERT_PTR_NOT_NULL_FATAL(fsa); /* * Lettura e caricamento eventi nell'array */ while(fgets(record,LRECORD + 2,fsa) != NULL) { CU_ASSERT_EQUAL_FATAL(record[LRECORD], '\n'); record[LRECORD]='\0'; strncpy(pbu[i],record,LRECORD+1); CU_TEST_FATAL(i < MAXNTEST); ev[i]=convertiRecord(record); CU_ASSERT_NOT_EQUAL_FATAL(ev[i],NULL); i++; } fclose(fsa); printf("lette %d voci\n",i); /* * Trasformazione voci nel formato stringa */ for ( l=0; l<i; l++ ) { int ret; /* printf("confron ta la mia %s, che viene da %s,%s,%s, con la sua %s\n", pb, ev[l]->data, ev[l]->utente, ev[l]->descrizione ,pbu[l]); */ convertiEvento(ev[l],pb); /* printf("confronta la mia %s, che viene da %s con la sua %s\n", pb, ev[l]->data ,pbu[l]); */ ret=strncmp(pbu[l],pb,LRECORD+1); CU_ASSERT_EQUAL_FATAL(ret, 0); } /* * Verifica funzione di matchPattern */ for (k=0;pattern[k]!=NULL; k++) { int cont = 0; for(l=0;l<i;l++) { cont+=matchPattern(pattern[k],ev[l]); /* printf(" pattern %s : %d occurrences \n",pattern[k],cont);*/ } CU_ASSERT_EQUAL_FATAL(cont, npatternmatch[k]); } /* * Verifica funzione di matchData */ for (k=0;date[k]!=NULL; k++) { int cont = 0; for(l=0;l<i;l++) { cont+=matchData(date[k],ev[l]); } /* printf("cont: %d nmatch %d\n", cont, nmatch[k]); */ CU_ASSERT_EQUAL_FATAL(cont, nmatch[k]); } /* * Test di creazione di una nuova agenda */ fsa=fopen(ftest,"w"); CU_ASSERT_PTR_NOT_NULL_FATAL(fsa); for ( l=0; l<i; l++ ) { convertiEvento(ev[l],pb); CU_ASSERT_NOT_EQUAL_FATAL(fputs(pb,fsa), EOF); fputs("\n",fsa); } fclose(fsa); }
// Decode a Denon message. // // Args: // results: Ptr to the data to decode and where to store the decode result. // nbits: Expected nr. of data bits. (Typically DENON_BITS) // Returns: // boolean: True if it can decode it, false if it can't. // // Status: BETA / Should work fine. // // Ref: // https://github.com/z3t0/Arduino-IRremote/blob/master/ir_Denon.cpp bool IRrecv::decodeDenon(decode_results *results, uint16_t nbits, bool strict) { // Compliance if (strict) { switch (nbits) { case DENON_BITS: case DENON_48_BITS: case kDenonLegacyBits: break; default: return false; } } // Denon uses the Sharp & Panasonic(Kaseikyo) protocol for some // devices, so check for those first. // It is not exactly like Sharp's protocols, but close enough. // e.g. The expansion bit is not set for Denon vs. set for Sharp. // Ditto for Panasonic, it's the same except for a different // manufacturer code. if (!decodeSharp(results, nbits, true, false) && !decodePanasonic(results, nbits, true, kDenonManufacturer)) { // We couldn't decode it as expected, so try the old legacy method. // NOTE: I don't think this following protocol actually exists. // Looks like a partial version of the Sharp protocol. // Check we have enough data if (results->rawlen < 2 * nbits + kHeader + kFooter - 1) return false; if (strict && nbits != kDenonLegacyBits) return false; uint64_t data = 0; uint16_t offset = kStartOffset; // Header if (!matchMark(results->rawbuf[offset], kDenonHdrMark)) return false; // Calculate how long the common tick time is based on the header mark. uint32_t m_tick = results->rawbuf[offset++] * kRawTick / kDenonHdrMarkTicks; if (!matchSpace(results->rawbuf[offset], kDenonHdrSpace)) return false; uint32_t s_tick = results->rawbuf[offset++] * kRawTick / kDenonHdrSpaceTicks; // Data match_result_t data_result = matchData(&(results->rawbuf[offset]), nbits, kDenonBitMarkTicks * m_tick, kDenonOneSpaceTicks * s_tick, kDenonBitMarkTicks * m_tick, kDenonZeroSpaceTicks * s_tick); if (data_result.success == false) return false; data = data_result.data; offset += data_result.used; // Footer if (!matchMark(results->rawbuf[offset++], kDenonBitMarkTicks * m_tick)) return false; // Success results->bits = nbits; results->value = data; results->address = 0; results->command = 0; } // Legacy decode. // Compliance if (strict && nbits != results->bits) return false; // Success results->decode_type = DENON; return true; }
bool Regex::matches(const std::string& str) const { ScopedMatchData matchData(mPCRE); return (matchData.match(str) > 0); }
NS_IMETHODIMP GnomeKeyring::ModifyLogin(nsILoginInfo *oldLogin, nsISupports *modLogin) { nsresult interfaceok; /* If the second argument is an nsILoginInfo, * just remove the old login and add the new one */ nsCOMPtr<nsILoginInfo> newLogin( do_QueryInterface(modLogin, &interfaceok) ); if (interfaceok == NS_OK) { nsresult rvremovelogin = RemoveLogin(oldLogin); nsresult rvaddlogin = AddLogin(newLogin); if(NS_FAILED(rvremovelogin)) { return rvremovelogin; } else { return rvaddlogin; } } /* Otherwise, it has to be an nsIPropertyBag. * Let's get the attributes from the old login, then append the ones * fetched from the property bag. Gracefully, if an attribute appears * twice in an attribut list, the last value is stored. */ nsCOMPtr<nsIPropertyBag> matchData( do_QueryInterface(modLogin, &interfaceok) ); if (interfaceok != NS_OK) { return interfaceok; } GnomeKeyringResult result; AutoAttributeList attributes; newLoginInfoAttributes(&attributes); appendAttributesFromLogin(oldLogin, attributes); // We need the id of the keyring item to set its attributes. AutoFoundList foundList; result = findLoginItems(attributes, &foundList); MGK_GK_CHECK_NS(result); PRUint32 i = 0, id; for (GList* l = foundList; l != NULL; l = l->next, i++) { GnomeKeyringFound* found = static_cast<GnomeKeyringFound*>(l->data); id = found->item_id; if (i >= 1) { NS_ERROR("found more than one item to edit"); return NS_ERROR_FAILURE; } } // set new attributes appendAttributesFromBag(matchData.get(), attributes); result = gnome_keyring_item_set_attributes_sync(keyringName.get(), id, attributes); MGK_GK_CHECK_NS(result); // set new iteminfo, e.g. password AutoItemInfo itemInfo; result = gnome_keyring_item_get_info_sync(keyringName.get(), id, &itemInfo); MGK_GK_CHECK_NS(result); appendItemInfoFromBag(matchData.get(), itemInfo); result = gnome_keyring_item_set_info_sync(keyringName.get(), id, itemInfo); MGK_GK_CHECK_NS(result); return NS_OK; }