我有以下数据
let data = r#"title1
title1 line1
title1 line2
sep/
title2
title2 line1
title2 line2
title2 line3
sep/
title3
title3 line1
sep/"#;
Run Code Online (Sandbox Code Playgroud)
基本上它代表三个条目:
struct Entry {
title: String,
body: String,
}
Run Code Online (Sandbox Code Playgroud)
每个条目都有标题和正文。标题消耗单行(不包括行结尾),正文消耗以下所有行,直到遇到分隔线 ( sep/)。我想要的结果是一个条目向量。我如何使用 nom 来解析它?我对 nom 很陌生,我无法让各个部分一起工作并形成一个有效的解析器。以下是我所拥有的:
use nom::IResult;
use nom::branch::alt;
use nom::bytes::complete::{tag, take_until, is_not, is_a};
use nom::error::ErrorKind::ParseTo;
use nom::sequence::{pair, tuple, delimited, terminated};
use nom::combinator::opt;
use nom::error::{Error, ErrorKind};
use nom::character::complete::line_ending;
use nom::regexp::str::{re_find, re_match, re_matches, re_capture};
use nom::multi::many0;
struct Entry {
title: String,
body: String,
}
fn get_entry_title(i: &str) …Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的程序:
fn main() {
let y = format!("{:0>3}", 11);
println!("{}", y);
}
Run Code Online (Sandbox Code Playgroud)
输出是字符串011。问题是宽度说明符 3 in{:0>3}来自这样的变量:
fn main() {
let x = 3usize;
let y = format!("{:0>3}", 11);
println!("{}", y);
}
Run Code Online (Sandbox Code Playgroud)
如何使用变量x替换3in {:0>3}?
我在https://github.com/BurntSushi/memchr上偶然发现了一个名为 memchr 的 Rust 库。该网站指出
该库为字符串搜索原语提供了高度优化的例程。
我搜索了一下,发现“原始”是编程语言计算中的一个术语。维基百科指出
在计算中,语言原语是编程语言中最简单的元素。原语是给定机器的程序员可用的最小“处理单元”,或者可以是语言中表达式的原子元素。
但我仍然无法完全理解它。谁能给我一些像 Javascript 这样的语言中的原语示例吗?“字符串搜索原语”到底是什么?
现在我已经反转了字符串和正则表达式以使用正则表达式模拟 rfind 。下面是一个示例程序:
#[static_init::dynamic]
// static r: Regex = regex::Regex::new(r"a\d").unwrap();
static r: Regex = regex::Regex::new(r"\da").unwrap();
let mut s = "123a123a456";
let sr = s.chars().rev().collect::<String>();
let option = r.find(&sr).unwrap();
let start = s.chars().count() - option.end();
let end = s.chars().count() - option.start();
println!("start: {:#?}", start);
println!("end: {:#?}", end);
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我必须将正则表达式从a\dto\da以及字符串反转s以模拟rfind操作。有更容易的方法吗?谢谢。
我对 Dart 很陌生,仍在学习中。据我了解,Dart 在不同的隔离区中执行代码。一个隔离可以启动另一个隔离来执行一些长时间运行的代码。对于每个隔离,都有一个线程和为其分配一些内存。这些隔离体就像一群小虚拟机一样被隔离。
我还从 Dart 文档中了解到 Dart 是一种单线程语言。但是,想一想,每个隔离都有自己的线程。如果isolate A有线程t1,isolate B有线程t2,那么t1和t2就不是同一个线程,对吗?
如果t1和t2是同一个线程,那么t1和t2就不能同时执行代码,这是可笑的。所以,t1和t2必须是不同的线程。
如果是这样,为什么我们说 Dart 是单线程语言呢?
以下文本是oracle文档的摘录Oracle®DatabasePL/SQL语言参考11g第1版(11.1):
未处理的异常也会影响子程序.如果成功退出子程序,PL/SQL会将值分配给OUT参数.但是,如果退出时出现未处理的异常,则PL/SQL不会为OUT参数赋值(除非它们是NOCOPY参数).此外,如果存储的子程序因未处理的异常而失败,则PL/SQL不会回滚子程序完成的数据库工作.
注意粗体文字,这是真的吗?我很好奇,所以我写了下面的例子来测试它.
-- create a test table
CREATE TABLE e AS SELECT * FROM HR.EMPLOYEES;
-- create p1 which will update a row in table e
CREATE OR REPLACE PROCEDURE p1
IS
ex EXCEPTION;
row e%ROWTYPE;
BEGIN
select * into row from e where employee_id=100;
row.employee_id := 100;
row.first_name := 'yang';
-- update
UPDATE e set ROW = row where employee_id = 100;
-- and raise an error
RAISE ex;
END;
BEGIN
-- call the upper …Run Code Online (Sandbox Code Playgroud) 我使用TOAD进行PL/SQL开发.在TOAD中,当我输入程序名称并按f4时,我可以看到此程序的源代码.我认为TOAD从v $ sqltext视图中获取源代码.为了证实我的想法,我写了一个查询:
select * from v$sqltext
Run Code Online (Sandbox Code Playgroud)
但是当我执行上层查询时,Oracle给出了一个错误:
ORA-00942:表或视图不存在00942. 00000 - "表或视图不存在"*原因:
*操作:行错误:29列:15
所以我认为TOAD从其他地方而不是v $ sqltext视图获取程序的源代码.谁能告诉我这件事?十分感谢.
我知道coldfusion builder已经发布用于开发coldfusion 9应用程序.现在我的问题是coldfusion builder是否支持COLDFUSION 8开发?十分感谢.
如何使用java获取位于Web服务器上的js文件,然后执行js文件中的函数并获取结果并在java中使用结果.
你们能给我一些代码片段吗?十分感谢.
我正在使用spring,所有带注释的实体类信息都放在ApplicationContext.xml中.我正在使用MySql数据库,现在如何在hibernate中使用SchemaExport函数来创建表?我的应用程序无法自动创建表,虽然我已设置<prop key="hbm2ddl.auto">create</prop>.这是我的ApplicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql:///edde" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>com.edde.Book</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="current_session_context_class">thread</prop>
<prop key="show_sql">true</prop>
<prop key="hbm2ddl.auto">create</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.use_sql_comments">true</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
</bean> …Run Code Online (Sandbox Code Playgroud) rust ×3
java ×2
oracle ×2
plsql ×2
coldfusion ×1
dart ×1
definition ×1
exception ×1
format ×1
hibernate ×1
javascript ×1
mysql ×1
nom ×1
ora-00942 ×1
regex ×1
spring ×1
toad ×1
transactions ×1