Reps readInput(std::string& molecule) { std::ifstream infile("data.txt"); std::string line; std::regex rex("(\\w+) => (\\w+)"); std::smatch match; Reps replacements; while (std::getline(infile, line)) { if (std::regex_match(line, match, rex)) { if (match.size() < 3) return replacements; replacements.insert(std::make_pair(match[1], match[2])); } else { molecule = line; } } return replacements; }
/*! Replace all variables in the text by it's values \param text Text for processing \param locals Local dictionary of variables return New string */ QString VariablesManager::replaceAllVariables( const QString& _text, bool quotedValues, const VariablesManager::Dictionary& locals ) const { QString text = _text; int p = 0; QRegExp rex( "(\\$(?:\\w|\\s|'|\\.|_|-)+\\$)" ); // search and interpret values QList<QString> findedVariables; while ( ( p = rex.indexIn( text, p ) ) != -1 ) { // got keyword const QString s = rex.capturedTexts().value( 1 ); findedVariables.append( s ); p += rex.matchedLength(); } // replace occurences foreach ( const QString& s, findedVariables ) { QString fuckDollar = QString(s).remove(s.size()-1,1).remove(0,1); bool toup = false; bool tolow = false; if (fuckDollar.endsWith (".upper")) { toup = true; fuckDollar.remove (".upper"); } else if (fuckDollar.endsWith (".lower")) { tolow = true; fuckDollar.remove (".lower"); } QString replaceWith = getVariable(fuckDollar,quotedValues,locals); if (toup) replaceWith = replaceWith.toUpper(); else if (tolow) replaceWith = replaceWith.toLower(); text.replace( s, replaceWith); text.replace( "\\n", "\n"); }
HAMIGAKI_BJAM_DECL string_list subst(context& ctx) { frame& f = ctx.current_frame(); const list_of_list& args = f.arguments(); const string_list& arg1 = args[0]; const std::string& str = arg1[0]; const std::string& pattern = bjam::convert_regex(arg1[1]); // Note: bjam's regex is not the same as "egrep" and "ECMAScript" boost::regex rex(pattern); string_list result; boost::smatch what; if (regex_search(str, what, rex)) { for (std::size_t i = 2, size = arg1.size(); i < size; ++i) result += what.format(arg1[i]); } return result; }
static QString guessMinimumWindowsVersion(const QtEnvironment &qt) { if (qt.mkspecName.startsWith(QLatin1String("winrt-"))) return QLatin1String("6.2"); if (!qt.mkspecName.startsWith(QLatin1String("win32-"))) return QString(); if (qt.architecture == QLatin1String("x86_64") || qt.architecture == QLatin1String("ia64")) { return QLatin1String("5.2"); } QRegExp rex(QLatin1String("^win32-msvc(\\d+)$")); if (rex.exactMatch(qt.mkspecName)) { int msvcVersion = rex.cap(1).toInt(); if (msvcVersion < 2012) return QLatin1String("5.0"); else return QLatin1String("5.1"); } return qt.qtMajorVersion < 5 ? QLatin1String("5.0") : QLatin1String("5.1"); }
template <typename TBuffer> inline typename TBuffer::cursor_t TR_X86OpCode::OpCode_t::encode(typename TBuffer::cursor_t cursor, uint8_t rexbits) const { TBuffer buffer(cursor); if (isX87()) { buffer.append(opcode); // Heuristics for X87 second byte opcode // It could be eliminated if GCC/MSVC fully support initializer list buffer.append((uint8_t)((modrm_opcode << 5) | (modrm_form << 3) | immediate_size)); return buffer; } // Prefixes TR::Instruction::REX rex(rexbits); rex.W = rex_w; // Use AVX if possible if (supportsAVX() && TR::CodeGenerator::getX86ProcessorInfo().supportsAVX()) { TR::Instruction::VEX<3> vex(rex, modrm_opcode); vex.m = escape; vex.L = vex_l; vex.p = prefixes; vex.opcode = opcode; if(vex.CanBeShortened()) { buffer.append(TR::Instruction::VEX<2>(vex)); } else { buffer.append(vex); } } else { switch (prefixes) { case PREFIX___: break; case PREFIX_66: buffer.append('\x66'); break; case PREFIX_F2: buffer.append('\xf2'); break; case PREFIX_F3: buffer.append('\xf3'); break; default: break; } // REX if (rex.value() || rexbits) { buffer.append(rex); } // OpCode escape switch (escape) { case ESCAPE_____: break; case ESCAPE_0F__: buffer.append('\x0f'); break; case ESCAPE_0F38: buffer.append('\x0f'); buffer.append('\x38'); break; case ESCAPE_0F3A: buffer.append('\x0f'); buffer.append('\x3a'); break; default: break; } // OpCode buffer.append(opcode); // ModRM if (modrm_form) { buffer.append(TR::Instruction::ModRM(modrm_opcode)); } } return buffer; }
/** @brief detect devices based on usb pid / vid. * @return list with usb VID / PID values. */ QMap<uint32_t, QString> System::listUsbDevices(void) { QMap<uint32_t, QString> usbids; // usb pid detection LOG_INFO() << "Searching for USB devices"; #if defined(Q_OS_LINUX) #if defined(LIBUSB1) libusb_device **devs; if(libusb_init(NULL) != 0) { LOG_ERROR() << "Initializing libusb-1 failed."; return usbids; } if(libusb_get_device_list(NULL, &devs) < 1) { LOG_ERROR() << "Error getting device list."; return usbids; } libusb_device *dev; int i = 0; while((dev = devs[i++]) != NULL) { QString name; unsigned char buf[256]; uint32_t id; struct libusb_device_descriptor descriptor; if(libusb_get_device_descriptor(dev, &descriptor) == 0) { id = descriptor.idVendor << 16 | descriptor.idProduct; libusb_device_handle *dh; if(libusb_open(dev, &dh) == 0) { libusb_get_string_descriptor_ascii(dh, descriptor.iManufacturer, buf, 256); name += QString::fromLatin1((char*)buf) + " "; libusb_get_string_descriptor_ascii(dh, descriptor.iProduct, buf, 256); name += QString::fromLatin1((char*)buf); libusb_close(dh); } if(name.isEmpty()) name = tr("(no description available)"); if(id) { usbids.insertMulti(id, name); LOG_INFO("USB: 0x%08x, %s", id, name.toLocal8Bit().data()); } } } libusb_free_device_list(devs, 1); libusb_exit(NULL); #else usb_init(); usb_find_busses(); usb_find_devices(); struct usb_bus *b; b = usb_busses; while(b) { if(b->devices) { struct usb_device *u; u = b->devices; while(u) { uint32_t id; id = u->descriptor.idVendor << 16 | u->descriptor.idProduct; // get identification strings usb_dev_handle *dev; QString name; char string[256]; int res; dev = usb_open(u); if(dev) { if(u->descriptor.iManufacturer) { res = usb_get_string_simple(dev, u->descriptor.iManufacturer, string, sizeof(string)); if(res > 0) name += QString::fromLatin1(string) + " "; } if(u->descriptor.iProduct) { res = usb_get_string_simple(dev, u->descriptor.iProduct, string, sizeof(string)); if(res > 0) name += QString::fromLatin1(string); } usb_close(dev); } if(name.isEmpty()) name = tr("(no description available)"); if(id) { usbids.insertMulti(id, name); LOG_INFO() << "USB:" << QString("0x%1").arg(id, 8, 16) << name; } u = u->next; } } b = b->next; } #endif #endif #if defined(Q_OS_MACX) kern_return_t result = KERN_FAILURE; CFMutableDictionaryRef usb_matching_dictionary; io_iterator_t usb_iterator = IO_OBJECT_NULL; usb_matching_dictionary = IOServiceMatching(kIOUSBDeviceClassName); result = IOServiceGetMatchingServices(kIOMasterPortDefault, usb_matching_dictionary, &usb_iterator); if(result) { LOG_ERROR() << "USB: IOKit: Could not get matching services."; return usbids; } io_object_t usbCurrentObj; while((usbCurrentObj = IOIteratorNext(usb_iterator))) { uint32_t id; QString name; /* get vendor ID */ CFTypeRef vidref = NULL; int vid = 0; vidref = IORegistryEntryCreateCFProperty(usbCurrentObj, CFSTR("idVendor"), kCFAllocatorDefault, 0); CFNumberGetValue((CFNumberRef)vidref, kCFNumberIntType, &vid); CFRelease(vidref); /* get product ID */ CFTypeRef pidref = NULL; int pid = 0; pidref = IORegistryEntryCreateCFProperty(usbCurrentObj, CFSTR("idProduct"), kCFAllocatorDefault, 0); CFNumberGetValue((CFNumberRef)pidref, kCFNumberIntType, &pid); CFRelease(pidref); id = vid << 16 | pid; /* get product vendor */ char vendor_buf[256]; CFIndex vendor_buflen = 256; CFTypeRef vendor_name_ref = NULL; vendor_name_ref = IORegistryEntrySearchCFProperty(usbCurrentObj, kIOServicePlane, CFSTR("USB Vendor Name"), kCFAllocatorDefault, 0); if(vendor_name_ref != NULL) { CFStringGetCString((CFStringRef)vendor_name_ref, vendor_buf, vendor_buflen, kCFStringEncodingUTF8); name += QString::fromUtf8(vendor_buf) + " "; CFRelease(vendor_name_ref); } else { name += QObject::tr("(unknown vendor name) "); } /* get product name */ char product_buf[256]; CFIndex product_buflen = 256; CFTypeRef product_name_ref = NULL; product_name_ref = IORegistryEntrySearchCFProperty(usbCurrentObj, kIOServicePlane, CFSTR("USB Product Name"), kCFAllocatorDefault, 0); if(product_name_ref != NULL) { CFStringGetCString((CFStringRef)product_name_ref, product_buf, product_buflen, kCFStringEncodingUTF8); name += QString::fromUtf8(product_buf); CFRelease(product_name_ref); } else { name += QObject::tr("(unknown product name)"); } if(id) { usbids.insertMulti(id, name); LOG_INFO() << "USB:" << QString("0x%1").arg(id, 8, 16) << name; } } IOObjectRelease(usb_iterator); #endif #if defined(Q_OS_WIN32) HDEVINFO deviceInfo; SP_DEVINFO_DATA infoData; DWORD i; // Iterate over all devices // by doing it this way it's unneccessary to use GUIDs which might be not // present in current MinGW. It also seemed to be more reliably than using // a GUID. // See KB259695 for an example. deviceInfo = SetupDiGetClassDevs(NULL, NULL, NULL, DIGCF_ALLCLASSES | DIGCF_PRESENT); infoData.cbSize = sizeof(SP_DEVINFO_DATA); for(i = 0; SetupDiEnumDeviceInfo(deviceInfo, i, &infoData); i++) { DWORD data; LPTSTR buffer = NULL; DWORD buffersize = 0; QString description; // get device descriptor first // for some reason not doing so results in bad things (tm) while(!SetupDiGetDeviceRegistryProperty(deviceInfo, &infoData, SPDRP_DEVICEDESC, &data, (PBYTE)buffer, buffersize, &buffersize)) { if(GetLastError() == ERROR_INSUFFICIENT_BUFFER) { if(buffer) free(buffer); // double buffer size to avoid problems as per KB888609 buffer = (LPTSTR)malloc(buffersize * 2); } else { break; } } if(!buffer) { LOG_WARNING() << "Got no device description" << "(SetupDiGetDeviceRegistryProperty), item" << i; continue; } description = QString::fromWCharArray(buffer); // now get the hardware id, which contains PID and VID. while(!SetupDiGetDeviceRegistryProperty(deviceInfo, &infoData, SPDRP_HARDWAREID, &data, (PBYTE)buffer, buffersize, &buffersize)) { if(GetLastError() == ERROR_INSUFFICIENT_BUFFER) { if(buffer) free(buffer); // double buffer size to avoid problems as per KB888609 buffer = (LPTSTR)malloc(buffersize * 2); } else { break; } } if(buffer) { // convert buffer text to upper case to avoid depending on the case of // the keys (W7 uses different casing than XP at least), in addition // XP may use "Vid_" and "Pid_". QString data = QString::fromWCharArray(buffer).toUpper(); QRegExp rex("USB\\\\VID_([0-9A-F]{4})&PID_([0-9A-F]{4}).*"); if(rex.indexIn(data) >= 0) { uint32_t id; id = rex.cap(1).toUInt(0, 16) << 16 | rex.cap(2).toUInt(0, 16); usbids.insert(id, description); LOG_INFO() << "USB:" << QString("0x%1").arg(id, 8, 16); } free(buffer); } } SetupDiDestroyDeviceInfoList(deviceInfo); #endif return usbids; }
bool RBtree<Key,Value,Compare>::exists(Key kee) { return rex(root, kee); }